diff --git a/noxfile.py b/noxfile.py index c59072072e..6f586c8730 100644 --- a/noxfile.py +++ b/noxfile.py @@ -8,9 +8,14 @@ # Whenever type-hints are completed on a file it should be added here so that # this file will continue to be checked by mypy. Errors from other files are # ignored. -STUB_FILES = { - "src/urllib3/packages/ssl_match_hostname/__init__.pyi", - "src/urllib3/packages/ssl_match_hostname/_implementation.pyi", +TYPED_FILES = { + "src/urllib3/exceptions.py", + "src/urllib3/fields.py", + "src/urllib3/packages/__init__.py", + "src/urllib3/packages/six.py", + "src/urllib3/packages/ssl_match_hostname/__init__.py", + "src/urllib3/packages/ssl_match_hostname/_implementation.py", + "src/urllib3/util/queue.py", } @@ -105,7 +110,7 @@ def lint(session): session.run("flake8", "setup.py", "docs", "dummyserver", "src", "test") session.log("mypy --strict src/urllib3") - errors = [] + all_errors, errors = [], [] process = subprocess.run( ["mypy", "--strict", "src/urllib3"], env=session.env, @@ -117,9 +122,11 @@ def lint(session): assert process.returncode in (0, 1) for line in process.stdout.split("\n"): + all_errors.append(line) filepath = line.partition(":")[0] - if filepath in STUB_FILES: + if filepath.replace(".pyi", ".py") in TYPED_FILES: errors.append(line) + session.log("all errors count: {}".format(len(all_errors))) if errors: session.error("\n" + "\n".join(sorted(set(errors)))) diff --git a/src/urllib3/exceptions.pyi b/src/urllib3/exceptions.pyi new file mode 100644 index 0000000000..1254abe7f6 --- /dev/null +++ b/src/urllib3/exceptions.pyi @@ -0,0 +1,55 @@ +from typing import Any, Optional, Union, Tuple, TYPE_CHECKING + +if TYPE_CHECKING: + from urllib3.connectionpool import ConnectionPool + +class HTTPError(Exception): ... +class HTTPWarning(Warning): ... + +class PoolError(HTTPError): + pool: ConnectionPool + def __init__(self, pool: ConnectionPool, message: str) -> None: ... + def __reduce__(self) -> Union[str, Tuple[Any, ...]]: ... + +class RequestError(PoolError): + url: str + def __init__(self, pool: ConnectionPool, url: str, message: str) -> None: ... + def __reduce__(self) -> Union[str, Tuple[Any, ...]]: ... + +class SSLError(HTTPError): ... +class ProxyError(HTTPError): ... +class DecodeError(HTTPError): ... +class ProtocolError(HTTPError): ... + +ConnectionError: ProtocolError + +class MaxRetryError(RequestError): + reason: str + def __init__( + self, pool: ConnectionPool, url: str, reason: Optional[str] + ) -> None: ... + +class HostChangedError(RequestError): + retries: int + def __init__(self, pool: ConnectionPool, url: str, retries: int) -> None: ... + +class TimeoutStateError(HTTPError): ... +class TimeoutError(HTTPError): ... +class ReadTimeoutError(TimeoutError, RequestError): ... +class ConnectTimeoutError(TimeoutError): ... +class EmptyPoolError(PoolError): ... +class ClosedPoolError(PoolError): ... +class LocationValueError(ValueError, HTTPError): ... + +class LocationParseError(LocationValueError): + location: str + def __init__(self, location: str) -> None: ... + +class ResponseError(HTTPError): + GENERIC_ERROR: Any + SPECIFIC_ERROR: Any + +class SecurityWarning(HTTPWarning): ... +class InsecureRequestWarning(SecurityWarning): ... +class SystemTimeWarning(SecurityWarning): ... +class InsecurePlatformWarning(SecurityWarning): ... diff --git a/src/urllib3/fields.pyi b/src/urllib3/fields.pyi new file mode 100644 index 0000000000..e1f3f90506 --- /dev/null +++ b/src/urllib3/fields.pyi @@ -0,0 +1,28 @@ +# Stubs for requests.packages.urllib3.fields (Python 3.4) + +from typing import Any, Callable, Mapping, Optional + +def guess_content_type(filename: str, default: str) -> str: ... +def format_header_param_rfc2231(name: str, value: str) -> str: ... +def format_header_param_html5(name: str, value: str) -> str: ... +def format_header_param(name: str, value: str) -> str: ... + +class RequestField: + data: Any + headers: Optional[Mapping[str, str]] + def __init__( + self, + name: str, + data: Any, + filename: Optional[str], + headers: Optional[Mapping[str, str]], + header_formatter: Callable[[str, str], str], + ) -> None: ... + @classmethod + def from_tuples( + cls, fieldname: str, value: str, header_formatter: Callable[[str, str], str] + ) -> RequestField: ... + def render_headers(self) -> str: ... + def make_multipart( + self, content_disposition: str, content_type: str, content_location: str + ) -> None: ... diff --git a/src/urllib3/packages/__init__.pyi b/src/urllib3/packages/__init__.pyi new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/urllib3/packages/six.pyi b/src/urllib3/packages/six.pyi new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/urllib3/util/queue.pyi b/src/urllib3/util/queue.pyi new file mode 100644 index 0000000000..e69de29bb2