Skip to content
Myr

add missing type hints to __init__(...) (#2938)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* add missing type hints to __init__ https://peps.python.org/pep-0484/ * add info to changelog * Update CHANGELOG.md * Update CHANGELOG.md ---------

authored by Petr Belskiy · committed by GitHub · parent c51e046 · Browse files · 11 files+24 added−20 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Kar Petrosyan <92274156+karpetrosyan@users.noreply.github.com>
  • Co-authored-by: Tom Christie <tom@tomchristie.com>

Diff stats

11 files+24 added−20 removed

  • tests:+3 added−3 removed
  • other:+21 added−17 removed

11 files+24 added−20 removed

modified:httpx/_transports/default.py+2 added-2 removed
100 unmodified lines
101}102103104class ResponseStream(SyncByteStream):105 def __init__(self, httpcore_stream: typing.Iterable[bytes]):105 def __init__(self, httpcore_stream: typing.Iterable[bytes]) -> None:106 self._httpcore_stream = httpcore_stream107108 def __iter__(self) -> typing.Iterator[bytes]:109 with map_httpcore_exceptions():
130 unmodified lines
240 self._pool.close()241242243class AsyncResponseStream(AsyncByteStream):244 def __init__(self, httpcore_stream: typing.AsyncIterable[bytes]):244 def __init__(self, httpcore_stream: typing.AsyncIterable[bytes]) -> None:245 self._httpcore_stream = httpcore_stream246247 async def __aiter__(self) -> typing.AsyncIterator[bytes]:248 with map_httpcore_exceptions():
130 unmodified lines
modified:httpx/_auth.py+2 added-2 removed
124 unmodified lines
125 """126127 def __init__(128 self, username: typing.Union[str, bytes], password: typing.Union[str, bytes]129 ):129 ) -> None:130 self._auth_header = self._build_auth_header(username, password)131132 def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:133 request.headers["Authorization"] = self._auth_header
11 unmodified lines
145 """146 Use a 'netrc' file to lookup basic auth credentials based on the url host.147 """148149 def __init__(self, file: typing.Optional[str] = None):149 def __init__(self, file: typing.Optional[str] = None) -> None:150 # Lazily import 'netrc'.151 # There's no need for us to load this module unless 'NetRCAuth' is being used.152 import netrc153
199 unmodified lines
modified:httpx/_client.py+3 added-3 removed
170 unmodified lines
171 ] = None,172 base_url: URLTypes = "",173 trust_env: bool = True,174 default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8",175 ):175 ) -> None:176 event_hooks = {} if event_hooks is None else event_hooks177178 self._base_url = self._enforce_trailing_slash(URL(base_url))179
461 unmodified lines
641 transport: typing.Optional[BaseTransport] = None,642 app: typing.Optional[typing.Callable[..., typing.Any]] = None,643 trust_env: bool = True,644 default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8",645 ):645 ) -> None:646 super().__init__(647 auth=auth,648 params=params,649 headers=headers,
716 unmodified lines
1366 transport: typing.Optional[AsyncBaseTransport] = None,1367 app: typing.Optional[typing.Callable[..., typing.Any]] = None,1368 trust_env: bool = True,1369 default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8",1370 ):1370 ) -> None:1371 super().__init__(1372 auth=auth,1373 params=params,1374 headers=headers,
632 unmodified lines
modified:httpx/_config.py+4 added-4 removed
65 unmodified lines
66 cert: typing.Optional[CertTypes] = None,67 verify: VerifyTypes = True,68 trust_env: bool = True,69 http2: bool = False,70 ):70 ) -> None:71 self.cert = cert72 self.verify = verify73 self.trust_env = trust_env74 self.http2 = http2
135 unmodified lines
210 connect: typing.Union[None, float, UnsetType] = UNSET,211 read: typing.Union[None, float, UnsetType] = UNSET,212 write: typing.Union[None, float, UnsetType] = UNSET,213 pool: typing.Union[None, float, UnsetType] = UNSET,214 ):214 ) -> None:215 if isinstance(timeout, Timeout):216 # Passed as a single explicit Timeout.217 assert connect is UNSET218 assert read is UNSET
76 unmodified lines
295 *,296 max_connections: typing.Optional[int] = None,297 max_keepalive_connections: typing.Optional[int] = None,298 keepalive_expiry: typing.Optional[float] = 5.0,299 ):299 ) -> None:300 self.max_connections = max_connections301 self.max_keepalive_connections = max_keepalive_connections302 self.keepalive_expiry = keepalive_expiry303
21 unmodified lines
325 *,326 ssl_context: typing.Optional[ssl.SSLContext] = None,327 auth: typing.Optional[typing.Tuple[str, str]] = None,328 headers: typing.Optional[HeaderTypes] = None,329 ):329 ) -> None:330 url = URL(url)331 headers = Headers(headers)332333 if url.scheme not in ("http", "https", "socks5"):
35 unmodified lines
modified:httpx/_content.py+2 added-2 removed
40 unmodified lines
4142class IteratorByteStream(SyncByteStream):43 CHUNK_SIZE = 65_5364445 def __init__(self, stream: Iterable[bytes]):45 def __init__(self, stream: Iterable[bytes]) -> None:46 self._stream = stream47 self._is_stream_consumed = False48 self._is_generator = inspect.isgenerator(stream)49
16 unmodified lines
6667class AsyncIteratorByteStream(AsyncByteStream):68 CHUNK_SIZE = 65_5366970 def __init__(self, stream: AsyncIterable[bytes]):70 def __init__(self, stream: AsyncIterable[bytes]) -> None:71 self._stream = stream72 self._is_stream_consumed = False73 self._is_generator = inspect.isasyncgen(stream)74
164 unmodified lines
modified:httpx/_decoders.py+1 added-1 removed
243 unmodified lines
244 """245 Handles incrementally decoding bytes into text246 """247248 def __init__(self, encoding: str = "utf-8"):248 def __init__(self, encoding: str = "utf-8") -> None:249 self.decoder = codecs.getincrementaldecoder(encoding)(errors="replace")250251 def decode(self, data: bytes) -> str:252 return self.decoder.decode(data)
72 unmodified lines
modified:httpx/_models.py+3 added-3 removed
316 unmodified lines
317 files: typing.Optional[RequestFiles] = None,318 json: typing.Optional[typing.Any] = None,319 stream: typing.Union[SyncByteStream, AsyncByteStream, None] = None,320 extensions: typing.Optional[RequestExtensions] = None,321 ):321 ) -> None:322 self.method = (323 method.decode("ascii").upper()324 if isinstance(method, bytes)325 else method.upper()
129 unmodified lines
455 request: typing.Optional[Request] = None,456 extensions: typing.Optional[ResponseExtensions] = None,457 history: typing.Optional[typing.List["Response"]] = None,458 default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8",459 ):459 ) -> None:460 self.status_code = status_code461 self.headers = Headers(headers)462463 self._request: typing.Optional[Request] = request
736 unmodified lines
1200 Wraps a `Request` instance up in a compatibility interface suitable1201 for use with `CookieJar` operations.1202 """12031204 def __init__(self, response: Response):1204 def __init__(self, response: Response) -> None:1205 self.response = response12061207 def info(self) -> email.message.Message:1208 info = email.message.Message()
6 unmodified lines
modified:tests/client/test_async_client.py+1 added-1 removed
210 unmodified lines
211212@pytest.mark.anyio213async def test_context_managed_transport_and_mount():214 class Transport(httpx.AsyncBaseTransport):215 def __init__(self, name: str):215 def __init__(self, name: str) -> None:216 self.name: str = name217 self.events: typing.List[str] = []218219 async def aclose(self):
154 unmodified lines
modified:tests/client/test_auth.py+1 added-1 removed
91 unmodified lines
92 """9394 requires_request_body = True9596 def __init__(self, repeat: int):96 def __init__(self, repeat: int) -> None:97 self.repeat = repeat9899 def auth_flow(100 self, request: httpx.Request
693 unmodified lines
modified:tests/client/test_client.py+1 added-1 removed
258 unmodified lines
259260261def test_context_managed_transport_and_mount():262 class Transport(httpx.BaseTransport):263 def __init__(self, name: str):263 def __init__(self, name: str) -> None:264 self.name: str = name265 self.events: typing.List[str] = []266267 def close(self):
193 unmodified lines
modified:CHANGELOG.md+4 added
4 unmodified lines
5The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).67## Unreleased89### Added1011* Add missing type hints to few `__init__()` methods. (#2938)1213## 0.25.1 (3rd November, 2023)1415### Added16
1038 unmodified lines