def _get(d, expected_type, key, default=None):
    # type: (Dict[str, Any], Type[T], str, Optional[T]) -> Optional[T]
    """Get value from dictionary and verify expected type."""
    if key not in d:
        return default
    value = d[key]
    if six.PY2 and expected_type is str:
        expected_type = six.string_types  # type: ignore
    if not isinstance(value, expected_type):
        raise DirectUrlValidationError(
            "{!r} has unexpected type for {} (expected {})".format(
                value, key, expected_type
            )
        )
    return value
Get value from dictionary and verify expected type.
product/gradle-plugin/src/main/python/pip/_internal/models/direct_url.py