Skip to content

Commit 87f39f1

Browse files
pbelskiykarpetrosyanlovelydinosaur
authored
add missing type hints to __init__(...) (#2938)
* 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>
1 parent c51e046 commit 87f39f1

File tree

11 files changed

+24
-20
lines changed

11 files changed

+24
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## Unreleased
88

9+
### Added
10+
11+
* Add missing type hints to few `__init__()` methods. (#2938)
12+
913
## 0.25.1 (3rd November, 2023)
1014

1115
### Added

httpx/_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class BasicAuth(Auth):
126126

127127
def __init__(
128128
self, username: typing.Union[str, bytes], password: typing.Union[str, bytes]
129-
):
129+
) -> None:
130130
self._auth_header = self._build_auth_header(username, password)
131131

132132
def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
@@ -146,7 +146,7 @@ class NetRCAuth(Auth):
146146
Use a 'netrc' file to lookup basic auth credentials based on the url host.
147147
"""
148148

149-
def __init__(self, file: typing.Optional[str] = None):
149+
def __init__(self, file: typing.Optional[str] = None) -> None:
150150
# Lazily import 'netrc'.
151151
# There's no need for us to load this module unless 'NetRCAuth' is being used.
152152
import netrc

httpx/_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def __init__(
172172
base_url: URLTypes = "",
173173
trust_env: bool = True,
174174
default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8",
175-
):
175+
) -> None:
176176
event_hooks = {} if event_hooks is None else event_hooks
177177

178178
self._base_url = self._enforce_trailing_slash(URL(base_url))
@@ -642,7 +642,7 @@ def __init__(
642642
app: typing.Optional[typing.Callable[..., typing.Any]] = None,
643643
trust_env: bool = True,
644644
default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8",
645-
):
645+
) -> None:
646646
super().__init__(
647647
auth=auth,
648648
params=params,
@@ -1367,7 +1367,7 @@ def __init__(
13671367
app: typing.Optional[typing.Callable[..., typing.Any]] = None,
13681368
trust_env: bool = True,
13691369
default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8",
1370-
):
1370+
) -> None:
13711371
super().__init__(
13721372
auth=auth,
13731373
params=params,

httpx/_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(
6767
verify: VerifyTypes = True,
6868
trust_env: bool = True,
6969
http2: bool = False,
70-
):
70+
) -> None:
7171
self.cert = cert
7272
self.verify = verify
7373
self.trust_env = trust_env
@@ -211,7 +211,7 @@ def __init__(
211211
read: typing.Union[None, float, UnsetType] = UNSET,
212212
write: typing.Union[None, float, UnsetType] = UNSET,
213213
pool: typing.Union[None, float, UnsetType] = UNSET,
214-
):
214+
) -> None:
215215
if isinstance(timeout, Timeout):
216216
# Passed as a single explicit Timeout.
217217
assert connect is UNSET
@@ -296,7 +296,7 @@ def __init__(
296296
max_connections: typing.Optional[int] = None,
297297
max_keepalive_connections: typing.Optional[int] = None,
298298
keepalive_expiry: typing.Optional[float] = 5.0,
299-
):
299+
) -> None:
300300
self.max_connections = max_connections
301301
self.max_keepalive_connections = max_keepalive_connections
302302
self.keepalive_expiry = keepalive_expiry
@@ -326,7 +326,7 @@ def __init__(
326326
ssl_context: typing.Optional[ssl.SSLContext] = None,
327327
auth: typing.Optional[typing.Tuple[str, str]] = None,
328328
headers: typing.Optional[HeaderTypes] = None,
329-
):
329+
) -> None:
330330
url = URL(url)
331331
headers = Headers(headers)
332332

httpx/_content.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def __aiter__(self) -> AsyncIterator[bytes]:
4242
class IteratorByteStream(SyncByteStream):
4343
CHUNK_SIZE = 65_536
4444

45-
def __init__(self, stream: Iterable[bytes]):
45+
def __init__(self, stream: Iterable[bytes]) -> None:
4646
self._stream = stream
4747
self._is_stream_consumed = False
4848
self._is_generator = inspect.isgenerator(stream)
@@ -67,7 +67,7 @@ def __iter__(self) -> Iterator[bytes]:
6767
class AsyncIteratorByteStream(AsyncByteStream):
6868
CHUNK_SIZE = 65_536
6969

70-
def __init__(self, stream: AsyncIterable[bytes]):
70+
def __init__(self, stream: AsyncIterable[bytes]) -> None:
7171
self._stream = stream
7272
self._is_stream_consumed = False
7373
self._is_generator = inspect.isasyncgen(stream)

httpx/_decoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class TextDecoder:
245245
Handles incrementally decoding bytes into text
246246
"""
247247

248-
def __init__(self, encoding: str = "utf-8"):
248+
def __init__(self, encoding: str = "utf-8") -> None:
249249
self.decoder = codecs.getincrementaldecoder(encoding)(errors="replace")
250250

251251
def decode(self, data: bytes) -> str:

httpx/_models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def __init__(
318318
json: typing.Optional[typing.Any] = None,
319319
stream: typing.Union[SyncByteStream, AsyncByteStream, None] = None,
320320
extensions: typing.Optional[RequestExtensions] = None,
321-
):
321+
) -> None:
322322
self.method = (
323323
method.decode("ascii").upper()
324324
if isinstance(method, bytes)
@@ -456,7 +456,7 @@ def __init__(
456456
extensions: typing.Optional[ResponseExtensions] = None,
457457
history: typing.Optional[typing.List["Response"]] = None,
458458
default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8",
459-
):
459+
) -> None:
460460
self.status_code = status_code
461461
self.headers = Headers(headers)
462462

@@ -1201,7 +1201,7 @@ class _CookieCompatResponse:
12011201
for use with `CookieJar` operations.
12021202
"""
12031203

1204-
def __init__(self, response: Response):
1204+
def __init__(self, response: Response) -> None:
12051205
self.response = response
12061206

12071207
def info(self) -> email.message.Message:

httpx/_transports/default.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def map_httpcore_exceptions() -> typing.Iterator[None]:
102102

103103

104104
class ResponseStream(SyncByteStream):
105-
def __init__(self, httpcore_stream: typing.Iterable[bytes]):
105+
def __init__(self, httpcore_stream: typing.Iterable[bytes]) -> None:
106106
self._httpcore_stream = httpcore_stream
107107

108108
def __iter__(self) -> typing.Iterator[bytes]:
@@ -241,7 +241,7 @@ def close(self) -> None:
241241

242242

243243
class AsyncResponseStream(AsyncByteStream):
244-
def __init__(self, httpcore_stream: typing.AsyncIterable[bytes]):
244+
def __init__(self, httpcore_stream: typing.AsyncIterable[bytes]) -> None:
245245
self._httpcore_stream = httpcore_stream
246246

247247
async def __aiter__(self) -> typing.AsyncIterator[bytes]:

tests/client/test_async_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ async def __aexit__(self, *args):
212212
@pytest.mark.anyio
213213
async def test_context_managed_transport_and_mount():
214214
class Transport(httpx.AsyncBaseTransport):
215-
def __init__(self, name: str):
215+
def __init__(self, name: str) -> None:
216216
self.name: str = name
217217
self.events: typing.List[str] = []
218218

tests/client/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class RepeatAuth(httpx.Auth):
9393

9494
requires_request_body = True
9595

96-
def __init__(self, repeat: int):
96+
def __init__(self, repeat: int) -> None:
9797
self.repeat = repeat
9898

9999
def auth_flow(

0 commit comments

Comments
 (0)