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 diff --git a/stubs/urllib3/urllib3/util/retry.pyi b/stubs/urllib3/urllib3/util/retry.pyi index d119a9207cd7..fe03433ab298 100644 --- a/stubs/urllib3/urllib3/util/retry.pyi +++ b/stubs/urllib3/urllib3/util/retry.pyi @@ -1,6 +1,11 @@ -from typing import Any +import logging +from _typeshed import Self +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 @@ -9,42 +14,71 @@ ProtocolError = exceptions.ProtocolError ReadTimeoutError = exceptions.ReadTimeoutError ResponseError = exceptions.ResponseError -log: Any +log: logging.Logger + +class RequestHistory(NamedTuple): + method: str | None + url: str | None + error: Exception | None + status: int | None + redirect_location: str | None class Retry: - DEFAULT_METHOD_WHITELIST: Any - BACKOFF_MAX: Any - total: Any - connect: Any - read: Any - redirect: Any - status_forcelist: Any - method_whitelist: Any - backoff_factor: Any - raise_on_redirect: Any + 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: Literal[True] | int | None + status: int | None + other: int | None + allowed_methods: Collection[str] | None + status_forcelist: Collection[int] + backoff_factor: float + raise_on_redirect: bool + raise_on_status: bool + 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: Self, **kw: Any) -> Self: ... @classmethod - def from_int(cls, retries, redirect=..., default=...): ... - 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_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: str | None = ..., + url: str | None = ..., + response: HTTPResponse | None = ..., + error: Exception | None = ..., + _pool: ConnectionPool | None = ..., + _stacktrace: TracebackType | None = ..., + ) -> Retry: ...