Skip to content

Update definition of constants in urllib3.util.retry #6892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions stubs/urllib3/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__
Expand All @@ -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
100 changes: 67 additions & 33 deletions stubs/urllib3/urllib3/util/retry.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...