From dc5908ea0c039ce920960ae48f0ec170cf5671ef Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 13:00:01 +0100 Subject: [PATCH 01/19] Update definition of constants in urllib3.util.retry --- stubs/urllib3/urllib3/util/retry.pyi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index d119a9207cd7..a63c5aba62af 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -12,8 +12,15 @@ ResponseError = exceptions.ResponseError log: Any class Retry: + DEFAULT_ALLOWED_METHODS: frozenset[str] + RETRY_AFTER_STATUS_CODES: frozenset[int] + DEFAULT_REMOVE_HEADERS_ON_REDIRECT: frozenset[list[str]] + DEFAULT_BACKOFF_MAX: int + + # Deprecated constants DEFAULT_METHOD_WHITELIST: Any BACKOFF_MAX: Any + total: Any connect: Any read: Any From 35905436addf7773a24655030b89eedab9304ff2 Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 14:02:26 +0100 Subject: [PATCH 02/19] DEFAULT_REMOVE_HEADERS_ON_REDIRECT is a frozenset[str] --- stubs/urllib3/urllib3/util/retry.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index a63c5aba62af..a576aea900ec 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -14,7 +14,7 @@ log: Any class Retry: DEFAULT_ALLOWED_METHODS: frozenset[str] RETRY_AFTER_STATUS_CODES: frozenset[int] - DEFAULT_REMOVE_HEADERS_ON_REDIRECT: frozenset[list[str]] + DEFAULT_REMOVE_HEADERS_ON_REDIRECT: frozenset[str] DEFAULT_BACKOFF_MAX: int # Deprecated constants From d37248a22b64150d4fff23840ad5b4f64a092294 Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 14:11:05 +0100 Subject: [PATCH 03/19] Mark default values as ClassVar --- stubs/urllib3/urllib3/util/retry.pyi | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index a576aea900ec..feb4a5092f47 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, ClassVar from .. import exceptions from ..response import HTTPResponse @@ -12,14 +12,14 @@ ResponseError = exceptions.ResponseError log: Any class Retry: - DEFAULT_ALLOWED_METHODS: frozenset[str] - RETRY_AFTER_STATUS_CODES: frozenset[int] - DEFAULT_REMOVE_HEADERS_ON_REDIRECT: frozenset[str] - DEFAULT_BACKOFF_MAX: int + DEFAULT_ALLOWED_METHODS: ClassVar[frozenset[str]] + RETRY_AFTER_STATUS_CODES: ClassVar[frozenset[int]] + DEFAULT_REMOVE_HEADERS_ON_REDIRECT: ClassVar[frozenset[str]] + DEFAULT_BACKOFF_MAX: ClassVar[int] # Deprecated constants - DEFAULT_METHOD_WHITELIST: Any - BACKOFF_MAX: Any + DEFAULT_METHOD_WHITELIST: ClassVar[Any] + BACKOFF_MAX: ClassVar[Any] total: Any connect: Any From 95cb6ce525f5940b4255eb466ea29e9b09e4dd1f Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 14:33:36 +0100 Subject: [PATCH 04/19] Remove deprecated constants and add more precise types for attributes --- stubs/urllib3/urllib3/util/retry.pyi | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index feb4a5092f47..1c1804d53822 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -1,4 +1,4 @@ -from typing import Any, ClassVar +from typing import Any, ClassVar, Iterable from .. import exceptions from ..response import HTTPResponse @@ -17,18 +17,20 @@ class Retry: DEFAULT_REMOVE_HEADERS_ON_REDIRECT: ClassVar[frozenset[str]] DEFAULT_BACKOFF_MAX: ClassVar[int] - # Deprecated constants - DEFAULT_METHOD_WHITELIST: ClassVar[Any] - BACKOFF_MAX: ClassVar[Any] - - total: Any - connect: Any - read: Any - redirect: Any - status_forcelist: Any - method_whitelist: Any - backoff_factor: Any - raise_on_redirect: Any + total: int + connect: int + read: int + redirect: int + status: int + other: int + status_forcelist: Iterable + allowed_methods: Iterable + backoff_factor: float + raise_on_status: bool + raise_on_redirect: bool + history: tuple + respect_retry_after_header: bool + remove_headers_on_redirect: Iterable def __init__( self, total=..., From e8e45d9e055929fa01ddba8a66539284b76bb990 Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 14:56:09 +0100 Subject: [PATCH 05/19] Update attributes and methods typing --- stubs/urllib3/urllib3/util/retry.pyi | 50 ++++++++++++++++++---------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index 1c1804d53822..c172673d5e59 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -1,4 +1,4 @@ -from typing import Any, ClassVar, Iterable +from typing import Any, ClassVar, Collection, Optional, Union from .. import exceptions from ..response import HTTPResponse @@ -11,26 +11,37 @@ ResponseError = exceptions.ResponseError log: Any + +class RequestHistory: + method: Optional[str] + url: Optional[str] + error: Optional[Exception] + status: Optional[int] + redirect_location: Optional[str] + + class Retry: DEFAULT_ALLOWED_METHODS: ClassVar[frozenset[str]] RETRY_AFTER_STATUS_CODES: ClassVar[frozenset[int]] DEFAULT_REMOVE_HEADERS_ON_REDIRECT: ClassVar[frozenset[str]] DEFAULT_BACKOFF_MAX: ClassVar[int] - total: int - connect: int - read: int - redirect: int - status: int - other: int - status_forcelist: Iterable - allowed_methods: Iterable + total: Optional[Union[bool, int]] + connect: Optional[int] + read: Optional[int] + redirect: Optional[Union[bool, int]] + status: Optional[int] + other: Optional[int] + allowed_methods: Optional[Collection[str]] + status_forcelist: Optional[Collection[int]] backoff_factor: float - raise_on_status: bool + backoff_max: float raise_on_redirect: bool - history: tuple + raise_on_status: bool + history: Optional[tuple[RequestHistory, ...]] respect_retry_after_header: bool - remove_headers_on_redirect: Iterable + remove_headers_on_redirect: Collection[str] + def __init__( self, total=..., @@ -42,18 +53,21 @@ class Retry: allowed_methods=..., status_forcelist=..., backoff_factor=..., + backoff_max=..., raise_on_redirect=..., raise_on_status=..., history=..., respect_retry_after_header=..., remove_headers_on_redirect=..., - method_whitelist=..., ) -> None: ... def new(self, **kw): ... @classmethod - def from_int(cls, retries, redirect=..., default=...): ... - def get_backoff_time(self): ... + def from_int(cls, retries, redirect=..., default=...) -> "Retry": ... + def get_backoff_time(self) -> float: ... + def parse_retry_after(self, retry_after: str) -> float: ... + def get_retry_after(self, response: HTTPResponse) -> Optional[float]: ... + def sleep_for_retry(self, response: HTTPResponse) -> bool: ... def sleep(self, response: HTTPResponse | None = ...) -> None: ... - def is_forced_retry(self, method, status_code): ... - def is_exhausted(self): ... - def increment(self, method=..., url=..., response=..., error=..., _pool=..., _stacktrace=...): ... + def is_retry(self, method: str, status_code: int, has_retry_after: bool) -> bool: ... + def is_exhausted(self) -> bool: ... + def increment(self, method=..., url=..., response=..., error=..., _pool=..., _stacktrace=...) -> "Retry": ... From 690c081de38413b7d8d0923edbc4441fa98cef11 Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 15:01:12 +0100 Subject: [PATCH 06/19] Use nex syntax for typing --- stubs/urllib3/urllib3/util/retry.pyi | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index c172673d5e59..f9abea2e64bc 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -1,4 +1,4 @@ -from typing import Any, ClassVar, Collection, Optional, Union +from typing import Any, ClassVar, Collection from .. import exceptions from ..response import HTTPResponse @@ -13,11 +13,11 @@ log: Any class RequestHistory: - method: Optional[str] - url: Optional[str] - error: Optional[Exception] - status: Optional[int] - redirect_location: Optional[str] + method: str | None + url: str | None + error: Exception | None + status: int | None + redirect_location: str | None class Retry: @@ -26,19 +26,19 @@ class Retry: DEFAULT_REMOVE_HEADERS_ON_REDIRECT: ClassVar[frozenset[str]] DEFAULT_BACKOFF_MAX: ClassVar[int] - total: Optional[Union[bool, int]] - connect: Optional[int] - read: Optional[int] - redirect: Optional[Union[bool, int]] - status: Optional[int] - other: Optional[int] - allowed_methods: Optional[Collection[str]] - status_forcelist: Optional[Collection[int]] + total: bool | int | None + connect: int | None + read: int | None + redirect: bool | int | None + status: int | None + other: int | None + allowed_methods: Collection[str] | None + status_forcelist: Collection[int] | None backoff_factor: float backoff_max: float raise_on_redirect: bool raise_on_status: bool - history: Optional[tuple[RequestHistory, ...]] + history: tuple[RequestHistory, ...] | None respect_retry_after_header: bool remove_headers_on_redirect: Collection[str] @@ -65,7 +65,7 @@ class Retry: def from_int(cls, retries, redirect=..., default=...) -> "Retry": ... def get_backoff_time(self) -> float: ... def parse_retry_after(self, retry_after: str) -> float: ... - def get_retry_after(self, response: HTTPResponse) -> Optional[float]: ... + def get_retry_after(self, response: HTTPResponse) -> float | None: ... def sleep_for_retry(self, response: HTTPResponse) -> bool: ... def sleep(self, response: HTTPResponse | None = ...) -> None: ... def is_retry(self, method: str, status_code: int, has_retry_after: bool) -> bool: ... From 7c87b9d00706bc424200a2588892b3f7ebae304a Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 15:06:31 +0100 Subject: [PATCH 07/19] Removing is_forced_retry unused stubs from allowedlist --- stubs/urllib3/@tests/stubtest_allowlist.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stubs/urllib3/@tests/stubtest_allowlist.txt b/stubs/urllib3/@tests/stubtest_allowlist.txt index 220aadc6510f..357586165f2f 100644 --- a/stubs/urllib3/@tests/stubtest_allowlist.txt +++ b/stubs/urllib3/@tests/stubtest_allowlist.txt @@ -8,7 +8,6 @@ urllib3.PoolManager.urlopen urllib3.ProxyManager.__init__ urllib3.ProxyManager.connection_from_host urllib3.ProxyManager.urlopen -urllib3.Retry.is_forced_retry urllib3._collections.HTTPHeaderDict.from_httplib urllib3._collections.HTTPHeaderDict.getlist urllib3._collections.RLock @@ -23,7 +22,6 @@ urllib3.connectionpool.HTTPConnectionPool.urlopen urllib3.connectionpool.HTTPSConnection.__init__ urllib3.connectionpool.HTTPSConnectionPool.__init__ urllib3.connectionpool.RequestMethods.request_encode_url -urllib3.connectionpool.Retry.is_forced_retry urllib3.connectionpool.VerifiedHTTPSConnection.__init__ urllib3.connectionpool.VerifiedHTTPSConnection.set_cert urllib3.fields.RequestField.__init__ @@ -40,9 +38,7 @@ urllib3.poolmanager.ProxyManager.connection_from_host urllib3.poolmanager.ProxyManager.urlopen urllib3.request.RequestMethods.request_encode_url urllib3.response.BrotliDecoder -urllib3.util.Retry.is_forced_retry urllib3.util.connection.poll urllib3.util.connection.select -urllib3.util.retry.Retry.is_forced_retry urllib3.util.ssl_.create_default_context urllib3.util.ssl_.ssl_wrap_socket From 7cd43512363f2efd91fa7618930ae5ca60da8dbd Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 15:14:16 +0100 Subject: [PATCH 08/19] Set default parameter values in methods --- stubs/urllib3/urllib3/util/retry.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index f9abea2e64bc..2678c7b565a9 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -62,12 +62,12 @@ class Retry: ) -> None: ... def new(self, **kw): ... @classmethod - def from_int(cls, retries, redirect=..., default=...) -> "Retry": ... + def from_int(cls, retries, redirect=..., default=...) -> Retry: ... def get_backoff_time(self) -> float: ... def parse_retry_after(self, retry_after: str) -> float: ... def get_retry_after(self, response: HTTPResponse) -> float | None: ... def sleep_for_retry(self, response: HTTPResponse) -> bool: ... - def sleep(self, response: HTTPResponse | None = ...) -> None: ... - def is_retry(self, method: str, status_code: int, has_retry_after: bool) -> bool: ... + def sleep(self, response: HTTPResponse | None = None) -> None: ... + def is_retry(self, method: str, status_code: int, has_retry_after: bool = False) -> bool: ... def is_exhausted(self) -> bool: ... - def increment(self, method=..., url=..., response=..., error=..., _pool=..., _stacktrace=...) -> "Retry": ... + def increment(self, method=..., url=..., response=..., error=..., _pool=..., _stacktrace=...) -> Retry: ... From 9b885ff002826d9f36473987ea15f1e223c189e7 Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 15:15:47 +0100 Subject: [PATCH 09/19] Fix black --- stubs/urllib3/urllib3/util/retry.pyi | 3 --- 1 file changed, 3 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index 2678c7b565a9..89c4dbab7876 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -11,7 +11,6 @@ ResponseError = exceptions.ResponseError log: Any - class RequestHistory: method: str | None url: str | None @@ -19,7 +18,6 @@ class RequestHistory: status: int | None redirect_location: str | None - class Retry: DEFAULT_ALLOWED_METHODS: ClassVar[frozenset[str]] RETRY_AFTER_STATUS_CODES: ClassVar[frozenset[int]] @@ -41,7 +39,6 @@ class Retry: history: tuple[RequestHistory, ...] | None respect_retry_after_header: bool remove_headers_on_redirect: Collection[str] - def __init__( self, total=..., From 13a091423f0f217d2b48cdc8c53852143ea35668 Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 15:18:38 +0100 Subject: [PATCH 10/19] Fixing flake8 issues --- stubs/urllib3/urllib3/util/retry.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index 89c4dbab7876..345b0a6ef63b 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -64,7 +64,7 @@ class Retry: def parse_retry_after(self, retry_after: str) -> float: ... def get_retry_after(self, response: HTTPResponse) -> float | None: ... def sleep_for_retry(self, response: HTTPResponse) -> bool: ... - def sleep(self, response: HTTPResponse | None = None) -> None: ... - def is_retry(self, method: str, status_code: int, has_retry_after: bool = False) -> bool: ... + def sleep(self, response: HTTPResponse | None = ...) -> None: ... + def is_retry(self, method: str, status_code: int, has_retry_after: bool = ...) -> bool: ... def is_exhausted(self) -> bool: ... def increment(self, method=..., url=..., response=..., error=..., _pool=..., _stacktrace=...) -> Retry: ... From 7bcf37232c2fd4bab5d6af38e7f0b68cbadf337d Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 15:47:52 +0100 Subject: [PATCH 11/19] Make urllib3 stubs consistent with the latest release --- stubs/urllib3/urllib3/util/retry.pyi | 58 ++++++++++++---------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index 345b0a6ef63b..a7ca59293cc6 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -1,4 +1,4 @@ -from typing import Any, ClassVar, Collection +from typing import Any, ClassVar from .. import exceptions from ..response import HTTPResponse @@ -11,34 +11,26 @@ ResponseError = exceptions.ResponseError log: Any -class RequestHistory: - method: str | None - url: str | None - error: Exception | None - status: int | None - redirect_location: str | None - class Retry: DEFAULT_ALLOWED_METHODS: ClassVar[frozenset[str]] RETRY_AFTER_STATUS_CODES: ClassVar[frozenset[int]] DEFAULT_REMOVE_HEADERS_ON_REDIRECT: ClassVar[frozenset[str]] DEFAULT_BACKOFF_MAX: ClassVar[int] - total: bool | int | None - connect: int | None - read: int | None - redirect: bool | int | None - status: int | None - other: int | None - allowed_methods: Collection[str] | None - status_forcelist: Collection[int] | None - backoff_factor: float - backoff_max: float - raise_on_redirect: bool - raise_on_status: bool - history: tuple[RequestHistory, ...] | None - respect_retry_after_header: bool - remove_headers_on_redirect: Collection[str] + total: Any + connect: Any + read: Any + redirect: Any + status: Any + other: Any + allowed_methods: Any + status_forcelist: Any + backoff_factor: Any + raise_on_redirect: Any + raise_on_status: Any + history: Any + respect_retry_after_header: Any + remove_headers_on_redirect: Any def __init__( self, total=..., @@ -50,21 +42,21 @@ class Retry: allowed_methods=..., status_forcelist=..., backoff_factor=..., - backoff_max=..., raise_on_redirect=..., raise_on_status=..., history=..., respect_retry_after_header=..., remove_headers_on_redirect=..., + method_whitelist=..., ) -> None: ... def new(self, **kw): ... @classmethod - def from_int(cls, retries, redirect=..., default=...) -> Retry: ... - def get_backoff_time(self) -> float: ... - def parse_retry_after(self, retry_after: str) -> float: ... - def get_retry_after(self, response: HTTPResponse) -> float | None: ... - def sleep_for_retry(self, response: HTTPResponse) -> bool: ... - def sleep(self, response: HTTPResponse | None = ...) -> None: ... - def is_retry(self, method: str, status_code: int, has_retry_after: bool = ...) -> bool: ... - def is_exhausted(self) -> bool: ... - def increment(self, method=..., url=..., response=..., error=..., _pool=..., _stacktrace=...) -> Retry: ... + def from_int(cls, retries, redirect=..., default=...): ... + def get_backoff_time(self): ... + def parse_retry_after(self, retry_after: str): ... + def get_retry_after(self, response: HTTPResponse): ... + def sleep_for_retry(self, response: HTTPResponse | None = ...): ... + def sleep(self, response: HTTPResponse | None = ...): ... + def is_retry(self, method: str, status_code: int, has_retry_after: bool = ...): ... + def is_exhausted(self): ... + def increment(self, method=..., url=..., response=..., error=..., _pool=..., _stacktrace=...): ... From b2e7e68ffb52b8338635c2db77c900513cb3cd62 Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 17:46:27 +0100 Subject: [PATCH 12/19] Add precise typing for attributes --- stubs/urllib3/urllib3/util/retry.pyi | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index a7ca59293cc6..eb23995b4917 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -1,4 +1,4 @@ -from typing import Any, ClassVar +from typing import Any, ClassVar, Collection from .. import exceptions from ..response import HTTPResponse @@ -17,20 +17,20 @@ class Retry: DEFAULT_REMOVE_HEADERS_ON_REDIRECT: ClassVar[frozenset[str]] DEFAULT_BACKOFF_MAX: ClassVar[int] - total: Any - connect: Any - read: Any - redirect: Any - status: Any - other: Any - allowed_methods: Any - status_forcelist: Any - backoff_factor: Any - raise_on_redirect: Any - raise_on_status: Any - history: Any - respect_retry_after_header: Any - remove_headers_on_redirect: Any + total: bool | int | None + connect: int | None + read: int | None + redirect: bool | int | None + status: int | None + other: int | None + allowed_methods: Collection[str] | None + status_forcelist: Collection[int] | None + backoff_factor: float + raise_on_redirect: bool + raise_on_status: bool + history: tuple[Any] | None + respect_retry_after_header: bool + remove_headers_on_redirect: Collection[str] def __init__( self, total=..., From 4e509dda90de716e795fe97933750377a4cde93b Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 18:41:19 +0100 Subject: [PATCH 13/19] Make type more precise and add return types in methods --- stubs/urllib3/urllib3/util/retry.pyi | 29 +++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index eb23995b4917..2fdc0c97cfc5 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -1,4 +1,5 @@ -from typing import Any, ClassVar, Collection +from typing import Any, ClassVar, Collection, NamedTuple +from typing_extensions import Literal from .. import exceptions from ..response import HTTPResponse @@ -11,6 +12,8 @@ ResponseError = exceptions.ResponseError log: Any +RequestHistory = NamedTuple + class Retry: DEFAULT_ALLOWED_METHODS: ClassVar[frozenset[str]] RETRY_AFTER_STATUS_CODES: ClassVar[frozenset[int]] @@ -20,17 +23,17 @@ class Retry: total: bool | int | None connect: int | None read: int | None - redirect: bool | int | None + redirect: Literal[True] | int | None status: int | None other: int | None allowed_methods: Collection[str] | None - status_forcelist: Collection[int] | None + status_forcelist: Collection[int] backoff_factor: float raise_on_redirect: bool raise_on_status: bool - history: tuple[Any] | None + history: tuple[RequestHistory, ...] | tuple[()] respect_retry_after_header: bool - remove_headers_on_redirect: Collection[str] + remove_headers_on_redirect: frozenset[str] def __init__( self, total=..., @@ -51,12 +54,12 @@ class Retry: ) -> None: ... def new(self, **kw): ... @classmethod - def from_int(cls, retries, redirect=..., default=...): ... + def from_int(cls, retries, redirect=..., default=...) -> Retry: ... def get_backoff_time(self): ... - def parse_retry_after(self, retry_after: str): ... - def get_retry_after(self, response: HTTPResponse): ... - def sleep_for_retry(self, response: HTTPResponse | None = ...): ... - def sleep(self, response: HTTPResponse | None = ...): ... - def is_retry(self, method: str, status_code: int, has_retry_after: bool = ...): ... - def is_exhausted(self): ... - def increment(self, method=..., url=..., response=..., error=..., _pool=..., _stacktrace=...): ... + def parse_retry_after(self, retry_after: str) -> float: ... + def get_retry_after(self, response: HTTPResponse) -> float | None: ... + def sleep_for_retry(self, response: HTTPResponse | None = ...) -> bool: ... + def sleep(self, response: HTTPResponse | None = ...) -> None: ... + def is_retry(self, method: str, status_code: int, has_retry_after: bool = ...) -> bool: ... + def is_exhausted(self) -> bool: ... + def increment(self, method=..., url=..., response=..., error=..., _pool=..., _stacktrace=...) -> Retry: ... From 7960ed1b826038b17c9067cdb5deace6669dce2e Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 18:49:16 +0100 Subject: [PATCH 14/19] Proper class definition for RequestHistory --- stubs/urllib3/urllib3/util/retry.pyi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index 2fdc0c97cfc5..3aa00dde097c 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -12,7 +12,13 @@ ResponseError = exceptions.ResponseError log: Any -RequestHistory = NamedTuple +class RequestHistory(NamedTuple): + method: str | None + url: str | None + error: Exception | None + status: int | None + redirect_location: str | None + class Retry: DEFAULT_ALLOWED_METHODS: ClassVar[frozenset[str]] From a604f0cd2ce1a5c1e0a478daa82a5a086c25318a Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Jan 2022 18:51:10 +0100 Subject: [PATCH 15/19] Fix black --- stubs/urllib3/urllib3/util/retry.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index 3aa00dde097c..6a4da84d29dc 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -19,7 +19,6 @@ class RequestHistory(NamedTuple): status: int | None redirect_location: str | None - class Retry: DEFAULT_ALLOWED_METHODS: ClassVar[frozenset[str]] RETRY_AFTER_STATUS_CODES: ClassVar[frozenset[int]] @@ -29,7 +28,7 @@ class Retry: total: bool | int | None connect: int | None read: int | None - redirect: Literal[True] | int | None + redirect: Literal[True] | int | None status: int | None other: int | None allowed_methods: Collection[str] | None From c4ca733d2d4eaef4f9815aba35444c500f032adf Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Wed, 12 Jan 2022 09:09:34 +0100 Subject: [PATCH 16/19] Add missing type annotations in methods --- stubs/urllib3/urllib3/util/retry.pyi | 45 +++++++++++++++------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index 6a4da84d29dc..6f9c054706cf 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -1,7 +1,10 @@ +import logging +from types import TracebackType from typing import Any, ClassVar, Collection, NamedTuple from typing_extensions import Literal from .. import exceptions +from ..connectionpool import ConnectionPool from ..response import HTTPResponse ConnectTimeoutError = exceptions.ConnectTimeoutError @@ -10,7 +13,7 @@ ProtocolError = exceptions.ProtocolError ReadTimeoutError = exceptions.ReadTimeoutError ResponseError = exceptions.ResponseError -log: Any +log: logging.Logger class RequestHistory(NamedTuple): method: str | None @@ -36,35 +39,35 @@ class Retry: backoff_factor: float raise_on_redirect: bool raise_on_status: bool - history: tuple[RequestHistory, ...] | tuple[()] + history: tuple[RequestHistory, ...] respect_retry_after_header: bool remove_headers_on_redirect: frozenset[str] def __init__( self, - total=..., - connect=..., - read=..., - redirect=..., - status=..., - other=..., - allowed_methods=..., - status_forcelist=..., - backoff_factor=..., - raise_on_redirect=..., - raise_on_status=..., - history=..., - respect_retry_after_header=..., - remove_headers_on_redirect=..., - method_whitelist=..., + total: bool | int | None = ..., + connect: int | None = ..., + read: int | None = ..., + redirect: bool | int | None = ..., + status: int | None = ..., + other: int | None = ..., + allowed_methods: Collection[str] | None = ..., + status_forcelist: Collection[int] | None = ..., + backoff_factor: float = ..., + raise_on_redirect: bool = ..., + raise_on_status: bool = ..., + history: tuple[RequestHistory, ...] | None = ..., + respect_retry_after_header: bool = ..., + remove_headers_on_redirect: Collection[str] = ..., + method_whitelist: Collection[str] | None = ... ) -> None: ... - def new(self, **kw): ... + def new(self, **kw: Any) -> Retry: ... @classmethod - def from_int(cls, retries, redirect=..., default=...) -> Retry: ... - def get_backoff_time(self): ... + def from_int(cls, retries: Retry | bool | int | None, redirect: bool | int | None =..., default: Retry | bool | int | None =...) -> Retry: ... + def get_backoff_time(self) -> float: ... def parse_retry_after(self, retry_after: str) -> float: ... def get_retry_after(self, response: HTTPResponse) -> float | None: ... def sleep_for_retry(self, response: HTTPResponse | None = ...) -> bool: ... def sleep(self, response: HTTPResponse | None = ...) -> None: ... def is_retry(self, method: str, status_code: int, has_retry_after: bool = ...) -> bool: ... def is_exhausted(self) -> bool: ... - def increment(self, method=..., url=..., response=..., error=..., _pool=..., _stacktrace=...) -> Retry: ... + def increment(self, method: str | None =..., url: str | None =..., response: HTTPResponse | None =..., error: Exception | None =..., _pool: ConnectionPool | None =..., _stacktrace: TracebackType | None =...) -> Retry: ... From 298f89f4081cb0e860cdc7920129c85f13b8fc5f Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Wed, 12 Jan 2022 09:11:49 +0100 Subject: [PATCH 17/19] format code with black --- stubs/urllib3/urllib3/util/retry.pyi | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index 6f9c054706cf..1156f339743b 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -58,11 +58,13 @@ class Retry: history: tuple[RequestHistory, ...] | None = ..., respect_retry_after_header: bool = ..., remove_headers_on_redirect: Collection[str] = ..., - method_whitelist: Collection[str] | None = ... + method_whitelist: Collection[str] | None = ..., ) -> None: ... def new(self, **kw: Any) -> Retry: ... @classmethod - def from_int(cls, retries: Retry | bool | int | None, redirect: bool | int | None =..., default: Retry | bool | int | None =...) -> Retry: ... + def from_int( + cls, retries: Retry | bool | int | None, redirect: bool | int | None = ..., default: Retry | bool | int | None = ... + ) -> Retry: ... def get_backoff_time(self) -> float: ... def parse_retry_after(self, retry_after: str) -> float: ... def get_retry_after(self, response: HTTPResponse) -> float | None: ... @@ -70,4 +72,12 @@ class Retry: def sleep(self, response: HTTPResponse | None = ...) -> None: ... def is_retry(self, method: str, status_code: int, has_retry_after: bool = ...) -> bool: ... def is_exhausted(self) -> bool: ... - def increment(self, method: str | None =..., url: str | None =..., response: HTTPResponse | None =..., error: Exception | None =..., _pool: ConnectionPool | None =..., _stacktrace: TracebackType | None =...) -> Retry: ... + def increment( + self, + method: str | None = ..., + url: str | None = ..., + response: HTTPResponse | None = ..., + error: Exception | None = ..., + _pool: ConnectionPool | None = ..., + _stacktrace: TracebackType | None = ..., + ) -> Retry: ... From bf3f7bf35f6eb96539767e16a99bdc16d8366982 Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Wed, 12 Jan 2022 09:26:50 +0100 Subject: [PATCH 18/19] Type new to be correct for sub-classes --- stubs/urllib3/urllib3/util/retry.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index 1156f339743b..427f7e70f1af 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -1,3 +1,5 @@ +from _typeshed import Self + import logging from types import TracebackType from typing import Any, ClassVar, Collection, NamedTuple @@ -60,7 +62,7 @@ class Retry: remove_headers_on_redirect: Collection[str] = ..., method_whitelist: Collection[str] | None = ..., ) -> None: ... - def new(self, **kw: Any) -> Retry: ... + def new(self, **kw: Any) -> Self: ... @classmethod def from_int( cls, retries: Retry | bool | int | None, redirect: bool | int | None = ..., default: Retry | bool | int | None = ... From 39296b981d0112da9b32d646264311a7e1256232 Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Wed, 12 Jan 2022 10:03:19 +0100 Subject: [PATCH 19/19] Add missing type for self --- stubs/urllib3/urllib3/util/retry.pyi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index 427f7e70f1af..fe03433ab298 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -1,6 +1,5 @@ -from _typeshed import Self - import logging +from _typeshed import Self from types import TracebackType from typing import Any, ClassVar, Collection, NamedTuple from typing_extensions import Literal @@ -62,7 +61,7 @@ class Retry: remove_headers_on_redirect: Collection[str] = ..., method_whitelist: Collection[str] | None = ..., ) -> None: ... - def new(self, **kw: Any) -> Self: ... + def new(self: Self, **kw: Any) -> Self: ... @classmethod def from_int( cls, retries: Retry | bool | int | None, redirect: bool | int | None = ..., default: Retry | bool | int | None = ...