From 14328f76ede2e95a4e78e63cd0327bbebdffce31 Mon Sep 17 00:00:00 2001 From: jpy-git Date: Mon, 3 Jan 2022 00:09:12 +0000 Subject: [PATCH 1/3] Complete requests.packages.urllib3.exceptions stubs --- stubs/requests/@tests/stubtest_allowlist.txt | 1 - .../requests/packages/urllib3/exceptions.pyi | 74 +++++++++++++++---- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/stubs/requests/@tests/stubtest_allowlist.txt b/stubs/requests/@tests/stubtest_allowlist.txt index 236bdeafdf90..b93e70a2e055 100644 --- a/stubs/requests/@tests/stubtest_allowlist.txt +++ b/stubs/requests/@tests/stubtest_allowlist.txt @@ -61,7 +61,6 @@ requests.packages.urllib3.connectionpool.Retry.is_forced_retry requests.packages.urllib3.connectionpool.Retry.sleep requests.packages.urllib3.connectionpool.VerifiedHTTPSConnection.__init__ requests.packages.urllib3.connectionpool.VerifiedHTTPSConnection.set_cert -requests.packages.urllib3.exceptions.ProxyError.__init__ requests.packages.urllib3.fields.RequestField.__init__ requests.packages.urllib3.fields.RequestField.from_tuples requests.packages.urllib3.filepost.RequestField.__init__ diff --git a/stubs/requests/requests/packages/urllib3/exceptions.pyi b/stubs/requests/requests/packages/urllib3/exceptions.pyi index ddb4e83ba77e..e3b97c614c6a 100644 --- a/stubs/requests/requests/packages/urllib3/exceptions.pyi +++ b/stubs/requests/requests/packages/urllib3/exceptions.pyi @@ -1,50 +1,94 @@ -from typing import Any +import socket +from email.errors import MessageDefect +from http.client import IncompleteRead as httplib_IncompleteRead +from typing import Any, Callable + +from requests.packages.urllib3 import HTTPResponse +from requests.packages.urllib3.connectionpool import ConnectionPool, HTTPConnection +from requests.packages.urllib3.util.retry import Retry class HTTPError(Exception): ... class HTTPWarning(Warning): ... +_TYPE_REDUCE_RESULT = tuple[Callable[..., Any], tuple[Any, ...]] + class PoolError(HTTPError): - pool: Any - def __init__(self, pool, message) -> None: ... - def __reduce__(self): ... + def __init__(self, pool: ConnectionPool, message: str) -> None: ... + def __reduce__(self) -> _TYPE_REDUCE_RESULT: ... class RequestError(PoolError): - url: Any - def __init__(self, pool, url, message) -> None: ... - def __reduce__(self): ... + def __init__(self, pool: ConnectionPool, url: str, message: str) -> None: ... + def __reduce__(self) -> _TYPE_REDUCE_RESULT: ... class SSLError(HTTPError): ... -class ProxyError(HTTPError): ... + +class ProxyError(HTTPError): + original_error: Exception + def __init__(self, message: str, error: Exception) -> None: ... + +class HTTPSProxyError(ProxyError): ... class DecodeError(HTTPError): ... class ProtocolError(HTTPError): ... -ConnectionError: Any +ConnectionError = ProtocolError class MaxRetryError(RequestError): reason: Any - def __init__(self, pool, url, reason=...) -> None: ... + def __init__(self, pool: ConnectionPool, url: str, reason: Exception | None = ...) -> None: ... class HostChangedError(RequestError): retries: Any - def __init__(self, pool, url, retries=...) -> None: ... + def __init__(self, pool: ConnectionPool, url: str, retries: Retry | int = ...) -> None: ... class TimeoutStateError(HTTPError): ... class TimeoutError(HTTPError): ... class ReadTimeoutError(TimeoutError, RequestError): ... class ConnectTimeoutError(TimeoutError): ... + +class NewConnectionError(ConnectTimeoutError, HTTPError): + def __init__(self, conn: HTTPConnection, message: str) -> None: ... + @property + def pool(self) -> HTTPConnection: ... + +class NameResolutionError(NewConnectionError): + def __init__(self, host: str, conn: HTTPConnection, reason: socket.gaierror) -> None: ... + class EmptyPoolError(PoolError): ... +class FullPoolError(PoolError): ... class ClosedPoolError(PoolError): ... class LocationValueError(ValueError, HTTPError): ... class LocationParseError(LocationValueError): - location: Any - def __init__(self, location) -> None: ... + def __init__(self, location: str) -> None: ... + +class URLSchemeUnknown(LocationValueError): + def __init__(self, scheme: str) -> None: ... class ResponseError(HTTPError): - GENERIC_ERROR: Any - SPECIFIC_ERROR: Any + GENERIC_ERROR: str + SPECIFIC_ERROR: str class SecurityWarning(HTTPWarning): ... class InsecureRequestWarning(SecurityWarning): ... class SystemTimeWarning(SecurityWarning): ... class InsecurePlatformWarning(SecurityWarning): ... +class SNIMissingWarning(HTTPWarning): ... +class DependencyWarning(HTTPWarning): ... +class ResponseNotChunked(ProtocolError, ValueError): ... +class BodyNotHttplibCompatible(HTTPError): ... + +class IncompleteRead(HTTPError, httplib_IncompleteRead): + def __init__(self, response: HTTPResponse, length: int) -> None: ... + def __repr__(self) -> str: ... + +class InvalidHeader(HTTPError): ... + +class ProxySchemeUnknown(AssertionError, URLSchemeUnknown): + def __init__(self, scheme: str | None) -> None: ... + +class ProxySchemeUnsupported(ValueError): ... + +class HeaderParsingError(HTTPError): + def __init__(self, defects: list[MessageDefect], unparsed_data: str | bytes | None) -> None: ... + +class UnrewindableBodyError(HTTPError): ... From 3746cd7527cf356666cd3bea7feba0c60c639d8a Mon Sep 17 00:00:00 2001 From: jpy-git Date: Mon, 3 Jan 2022 15:53:39 +0000 Subject: [PATCH 2/3] Use latest release not latest master --- .../requests/packages/urllib3/exceptions.pyi | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/stubs/requests/requests/packages/urllib3/exceptions.pyi b/stubs/requests/requests/packages/urllib3/exceptions.pyi index e3b97c614c6a..3f8983d306c8 100644 --- a/stubs/requests/requests/packages/urllib3/exceptions.pyi +++ b/stubs/requests/requests/packages/urllib3/exceptions.pyi @@ -1,10 +1,8 @@ -import socket from email.errors import MessageDefect from http.client import IncompleteRead as httplib_IncompleteRead from typing import Any, Callable -from requests.packages.urllib3 import HTTPResponse -from requests.packages.urllib3.connectionpool import ConnectionPool, HTTPConnection +from requests.packages.urllib3.connectionpool import ConnectionPool from requests.packages.urllib3.util.retry import Retry class HTTPError(Exception): ... @@ -24,9 +22,8 @@ class SSLError(HTTPError): ... class ProxyError(HTTPError): original_error: Exception - def __init__(self, message: str, error: Exception) -> None: ... + def __init__(self, message: str, error: Exception, *args: Any) -> None: ... -class HTTPSProxyError(ProxyError): ... class DecodeError(HTTPError): ... class ProtocolError(HTTPError): ... @@ -44,17 +41,8 @@ class TimeoutStateError(HTTPError): ... class TimeoutError(HTTPError): ... class ReadTimeoutError(TimeoutError, RequestError): ... class ConnectTimeoutError(TimeoutError): ... - -class NewConnectionError(ConnectTimeoutError, HTTPError): - def __init__(self, conn: HTTPConnection, message: str) -> None: ... - @property - def pool(self) -> HTTPConnection: ... - -class NameResolutionError(NewConnectionError): - def __init__(self, host: str, conn: HTTPConnection, reason: socket.gaierror) -> None: ... - +class NewConnectionError(ConnectTimeoutError, HTTPError): ... class EmptyPoolError(PoolError): ... -class FullPoolError(PoolError): ... class ClosedPoolError(PoolError): ... class LocationValueError(ValueError, HTTPError): ... @@ -78,7 +66,7 @@ class ResponseNotChunked(ProtocolError, ValueError): ... class BodyNotHttplibCompatible(HTTPError): ... class IncompleteRead(HTTPError, httplib_IncompleteRead): - def __init__(self, response: HTTPResponse, length: int) -> None: ... + def __init__(self, partial: bytes, expected: int | None) -> None: ... def __repr__(self) -> str: ... class InvalidHeader(HTTPError): ... From e58b16c23b106d4c411101ce69faaa2d4e30da71 Mon Sep 17 00:00:00 2001 From: jpy-git Date: Mon, 3 Jan 2022 15:58:06 +0000 Subject: [PATCH 3/3] remove unused allowlist entry --- stubs/requests/@tests/stubtest_allowlist.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/requests/@tests/stubtest_allowlist.txt b/stubs/requests/@tests/stubtest_allowlist.txt index b93e70a2e055..84784ba66eb1 100644 --- a/stubs/requests/@tests/stubtest_allowlist.txt +++ b/stubs/requests/@tests/stubtest_allowlist.txt @@ -55,7 +55,6 @@ requests.packages.urllib3.connectionpool.HTTPConnectionPool.urlopen requests.packages.urllib3.connectionpool.HTTPResponse.__init__ requests.packages.urllib3.connectionpool.HTTPSConnection.__init__ requests.packages.urllib3.connectionpool.HTTPSConnectionPool.__init__ -requests.packages.urllib3.connectionpool.ProxyError.__init__ requests.packages.urllib3.connectionpool.RequestMethods.request_encode_url requests.packages.urllib3.connectionpool.Retry.is_forced_retry requests.packages.urllib3.connectionpool.Retry.sleep