From 7a2127abda8cdca618dcbf75aebb22ff58aa8f1d Mon Sep 17 00:00:00 2001 From: Petr Belskiy Date: Mon, 13 Nov 2023 00:23:43 +0300 Subject: [PATCH 1/4] add missing type hints to __init__ https://peps.python.org/pep-0484/ --- httpx/_auth.py | 4 ++-- httpx/_client.py | 6 +++--- httpx/_config.py | 8 ++++---- httpx/_content.py | 4 ++-- httpx/_decoders.py | 2 +- httpx/_models.py | 6 +++--- httpx/_transports/default.py | 4 ++-- tests/client/test_async_client.py | 2 +- tests/client/test_auth.py | 2 +- tests/client/test_client.py | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/httpx/_auth.py b/httpx/_auth.py index c2c38f3945..66132500ff 100644 --- a/httpx/_auth.py +++ b/httpx/_auth.py @@ -126,7 +126,7 @@ class BasicAuth(Auth): def __init__( self, username: typing.Union[str, bytes], password: typing.Union[str, bytes] - ): + ) -> None: self._auth_header = self._build_auth_header(username, password) def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]: @@ -146,7 +146,7 @@ class NetRCAuth(Auth): Use a 'netrc' file to lookup basic auth credentials based on the url host. """ - def __init__(self, file: typing.Optional[str] = None): + def __init__(self, file: typing.Optional[str] = None) -> None: # Lazily import 'netrc'. # There's no need for us to load this module unless 'NetRCAuth' is being used. import netrc diff --git a/httpx/_client.py b/httpx/_client.py index cb475e0204..2c7ae030f5 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -172,7 +172,7 @@ def __init__( base_url: URLTypes = "", trust_env: bool = True, default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8", - ): + ) -> None: event_hooks = {} if event_hooks is None else event_hooks self._base_url = self._enforce_trailing_slash(URL(base_url)) @@ -642,7 +642,7 @@ def __init__( app: typing.Optional[typing.Callable[..., typing.Any]] = None, trust_env: bool = True, default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8", - ): + ) -> None: super().__init__( auth=auth, params=params, @@ -1367,7 +1367,7 @@ def __init__( app: typing.Optional[typing.Callable[..., typing.Any]] = None, trust_env: bool = True, default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8", - ): + ) -> None: super().__init__( auth=auth, params=params, diff --git a/httpx/_config.py b/httpx/_config.py index 45ed29ed70..05c096dfc3 100644 --- a/httpx/_config.py +++ b/httpx/_config.py @@ -67,7 +67,7 @@ def __init__( verify: VerifyTypes = True, trust_env: bool = True, http2: bool = False, - ): + ) -> None: self.cert = cert self.verify = verify self.trust_env = trust_env @@ -211,7 +211,7 @@ def __init__( read: typing.Union[None, float, UnsetType] = UNSET, write: typing.Union[None, float, UnsetType] = UNSET, pool: typing.Union[None, float, UnsetType] = UNSET, - ): + ) -> None: if isinstance(timeout, Timeout): # Passed as a single explicit Timeout. assert connect is UNSET @@ -296,7 +296,7 @@ def __init__( max_connections: typing.Optional[int] = None, max_keepalive_connections: typing.Optional[int] = None, keepalive_expiry: typing.Optional[float] = 5.0, - ): + ) -> None: self.max_connections = max_connections self.max_keepalive_connections = max_keepalive_connections self.keepalive_expiry = keepalive_expiry @@ -326,7 +326,7 @@ def __init__( ssl_context: typing.Optional[ssl.SSLContext] = None, auth: typing.Optional[typing.Tuple[str, str]] = None, headers: typing.Optional[HeaderTypes] = None, - ): + ) -> None: url = URL(url) headers = Headers(headers) diff --git a/httpx/_content.py b/httpx/_content.py index b16e12d954..0aaea33749 100644 --- a/httpx/_content.py +++ b/httpx/_content.py @@ -42,7 +42,7 @@ async def __aiter__(self) -> AsyncIterator[bytes]: class IteratorByteStream(SyncByteStream): CHUNK_SIZE = 65_536 - def __init__(self, stream: Iterable[bytes]): + def __init__(self, stream: Iterable[bytes]) -> None: self._stream = stream self._is_stream_consumed = False self._is_generator = inspect.isgenerator(stream) @@ -67,7 +67,7 @@ def __iter__(self) -> Iterator[bytes]: class AsyncIteratorByteStream(AsyncByteStream): CHUNK_SIZE = 65_536 - def __init__(self, stream: AsyncIterable[bytes]): + def __init__(self, stream: AsyncIterable[bytes]) -> None: self._stream = stream self._is_stream_consumed = False self._is_generator = inspect.isasyncgen(stream) diff --git a/httpx/_decoders.py b/httpx/_decoders.py index 500ce7ffc3..b4ac9a44af 100644 --- a/httpx/_decoders.py +++ b/httpx/_decoders.py @@ -245,7 +245,7 @@ class TextDecoder: Handles incrementally decoding bytes into text """ - def __init__(self, encoding: str = "utf-8"): + def __init__(self, encoding: str = "utf-8") -> None: self.decoder = codecs.getincrementaldecoder(encoding)(errors="replace") def decode(self, data: bytes) -> str: diff --git a/httpx/_models.py b/httpx/_models.py index 4e4162db1a..8a5e6280f3 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -318,7 +318,7 @@ def __init__( json: typing.Optional[typing.Any] = None, stream: typing.Union[SyncByteStream, AsyncByteStream, None] = None, extensions: typing.Optional[RequestExtensions] = None, - ): + ) -> None: self.method = ( method.decode("ascii").upper() if isinstance(method, bytes) @@ -456,7 +456,7 @@ def __init__( extensions: typing.Optional[ResponseExtensions] = None, history: typing.Optional[typing.List["Response"]] = None, default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8", - ): + ) -> None: self.status_code = status_code self.headers = Headers(headers) @@ -1201,7 +1201,7 @@ class _CookieCompatResponse: for use with `CookieJar` operations. """ - def __init__(self, response: Response): + def __init__(self, response: Response) -> None: self.response = response def info(self) -> email.message.Message: diff --git a/httpx/_transports/default.py b/httpx/_transports/default.py index 76c543ce4e..343c588f9f 100644 --- a/httpx/_transports/default.py +++ b/httpx/_transports/default.py @@ -102,7 +102,7 @@ def map_httpcore_exceptions() -> typing.Iterator[None]: class ResponseStream(SyncByteStream): - def __init__(self, httpcore_stream: typing.Iterable[bytes]): + def __init__(self, httpcore_stream: typing.Iterable[bytes]) -> None: self._httpcore_stream = httpcore_stream def __iter__(self) -> typing.Iterator[bytes]: @@ -241,7 +241,7 @@ def close(self) -> None: class AsyncResponseStream(AsyncByteStream): - def __init__(self, httpcore_stream: typing.AsyncIterable[bytes]): + def __init__(self, httpcore_stream: typing.AsyncIterable[bytes]) -> None: self._httpcore_stream = httpcore_stream async def __aiter__(self) -> typing.AsyncIterator[bytes]: diff --git a/tests/client/test_async_client.py b/tests/client/test_async_client.py index cc19e93d41..49664df589 100644 --- a/tests/client/test_async_client.py +++ b/tests/client/test_async_client.py @@ -212,7 +212,7 @@ async def __aexit__(self, *args): @pytest.mark.anyio async def test_context_managed_transport_and_mount(): class Transport(httpx.AsyncBaseTransport): - def __init__(self, name: str): + def __init__(self, name: str) -> None: self.name: str = name self.events: typing.List[str] = [] diff --git a/tests/client/test_auth.py b/tests/client/test_auth.py index fee515058b..9b1dd88f5e 100644 --- a/tests/client/test_auth.py +++ b/tests/client/test_auth.py @@ -93,7 +93,7 @@ class RepeatAuth(httpx.Auth): requires_request_body = True - def __init__(self, repeat: int): + def __init__(self, repeat: int) -> None: self.repeat = repeat def auth_flow( diff --git a/tests/client/test_client.py b/tests/client/test_client.py index b8245288ad..fcc6ec6a08 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -260,7 +260,7 @@ def __exit__(self, *args): def test_context_managed_transport_and_mount(): class Transport(httpx.BaseTransport): - def __init__(self, name: str): + def __init__(self, name: str) -> None: self.name: str = name self.events: typing.List[str] = [] From 19bad62ba98ed7a81ccc0468092e3a9682995f25 Mon Sep 17 00:00:00 2001 From: Petr Belskiy Date: Tue, 14 Nov 2023 09:55:29 +0300 Subject: [PATCH 2/4] add info to changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c6022b79c..dd52afb909 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased +* Add missing type hints to few `__init__()` methods + ## 0.25.1 (3rd November, 2023) * Add support for Python 3.12. (#2854) From 7195c61423ab103c2fa8d2aba18788ac48d9c2d9 Mon Sep 17 00:00:00 2001 From: Kar Petrosyan <92274156+karpetrosyan@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:09:43 +0400 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd52afb909..548d72a475 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased -* Add missing type hints to few `__init__()` methods +* Add missing type hints to few `__init__()` methods. (#2938) ## 0.25.1 (3rd November, 2023) From cdc27e23e3aee58a44814dc49a27695a8cb0e675 Mon Sep 17 00:00:00 2001 From: Kar Petrosyan <92274156+karpetrosyan@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:25:36 +0400 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 548d72a475..f34b575204 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased +### Added + * Add missing type hints to few `__init__()` methods. (#2938) ## 0.25.1 (3rd November, 2023)