]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
add missing type hints to __init__(...) (#2938)
authorPetr Belskiy <petr.belskiy@gmail.com>
Fri, 17 Nov 2023 13:58:51 +0000 (16:58 +0300)
committerGitHub <noreply@github.com>
Fri, 17 Nov 2023 13:58:51 +0000 (17:58 +0400)
* add missing type hints to __init__

https://peps.python.org/pep-0484/

* add info to changelog

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Kar Petrosyan <92274156+karpetrosyan@users.noreply.github.com>
Co-authored-by: Tom Christie <tom@tomchristie.com>
CHANGELOG.md
httpx/_auth.py
httpx/_client.py
httpx/_config.py
httpx/_content.py
httpx/_decoders.py
httpx/_models.py
httpx/_transports/default.py
tests/client/test_async_client.py
tests/client/test_auth.py
tests/client/test_client.py

index 4865b8dce97bf44ad17018f16cf80901758f3ba3..5b370ca5fa661e6e02cc9c4e6fbc2277b0f868f6 100644 (file)
@@ -6,6 +6,10 @@ 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)
 
 ### Added
index c2c38f39455f6fe8a357e618f9e1d162a418e309..66132500ff3bd3bb81694800d03f3b2258ab5c31 100644 (file)
@@ -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
index cb475e02045aafac34309e4b808e12c580e58d8f..2c7ae030f50e13cfa07a90a640aa0870e644856e 100644 (file)
@@ -172,7 +172,7 @@ class BaseClient:
         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 @@ class Client(BaseClient):
         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 @@ class AsyncClient(BaseClient):
         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,
index 45ed29ed70520bce8898317c9cf7a1795adf59c8..05c096dfc3103aec8971ce406c9aaee0155ba283 100644 (file)
@@ -67,7 +67,7 @@ class SSLConfig:
         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 @@ class Timeout:
         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 @@ class Limits:
         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 @@ class Proxy:
         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)
 
index b16e12d954327e7ecd5f05885bb8778a0fbfa047..0aaea33749a3d1ce41578c2ced4cce7d006c4b0f 100644 (file)
@@ -42,7 +42,7 @@ class ByteStream(AsyncByteStream, SyncByteStream):
 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 @@ class IteratorByteStream(SyncByteStream):
 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)
index 500ce7ffc3cc999085bf303833e2fa5ad98ea2ec..b4ac9a44af63cd5fb993144cf192a1c4a9991050 100644 (file)
@@ -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:
index 4e4162db1a847fc3f9033574684936a8720507fd..8a5e6280f3f3fc26dbdd140f7e24858fce4a983c 100644 (file)
@@ -318,7 +318,7 @@ class Request:
         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 @@ class Response:
         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 Cookies(typing.MutableMapping[str, str]):
         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:
index 76c543ce4e94b736303e7df76b16bcadedcc3b7a..343c588f9ff595bbcfa12538ced09b5ea1955261 100644 (file)
@@ -102,7 +102,7 @@ HTTPCORE_EXC_MAP = {
 
 
 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 @@ class HTTPTransport(BaseTransport):
 
 
 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]:
index cc19e93d4113f6f8b22b7f7478a66d212077d018..49664df5899dd477cd6dfa88fca2a0c947a0244c 100644 (file)
@@ -212,7 +212,7 @@ async def test_context_managed_transport():
 @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] = []
 
index fee515058b92a3f09738feaffc4b3b511024fda8..9b1dd88f5edcb696eedf90bc97ef5d394bda03ff 100644 (file)
@@ -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(
index b8245288ad8b1b599a605ccc265c56837e86e6b6..fcc6ec6a08ed6c89edff90e97c926171862e22ed 100644 (file)
@@ -260,7 +260,7 @@ def test_context_managed_transport():
 
 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] = []