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
Provenance
- Commit
87f39f1- Tree
a508733- Author
Petr Belskiy <petr.belskiy@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
c51e046
11 files changed+24 added−20 removed
modified:httpx/_transports/default.py+2 added-2 removed
100 unmodified lines101 }102 103 104 class 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_stream107 108 def __iter__(self) -> typing.Iterator[bytes]:109 with map_httpcore_exceptions():130 unmodified lines240 self._pool.close()241 242 243 class 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_stream246 247 async def __aiter__(self) -> typing.AsyncIterator[bytes]:248 with map_httpcore_exceptions():130 unmodified linesmodified:httpx/_auth.py+2 added-2 removed
124 unmodified lines125 """126 127 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)131 132 def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:133 request.headers["Authorization"] = self._auth_header11 unmodified lines145 """146 Use a 'netrc' file to lookup basic auth credentials based on the url host.147 """148 149- 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 linesmodified:httpx/_client.py+3 added-3 removed
170 unmodified lines171 ] = 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_hooks177 178 self._base_url = self._enforce_trailing_slash(URL(base_url))179 461 unmodified lines641 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 lines1366 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 linesmodified:httpx/_config.py+4 added-4 removed
65 unmodified lines66 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 = http2135 unmodified lines210 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 UNSET76 unmodified lines295 *,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 lines325 *,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)332 333 if url.scheme not in ("http", "https", "socks5"):35 unmodified linesmodified:httpx/_content.py+2 added-2 removed
40 unmodified lines41 42 class IteratorByteStream(SyncByteStream):43 CHUNK_SIZE = 65_53644 45- 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 lines66 67 class AsyncIteratorByteStream(AsyncByteStream):68 CHUNK_SIZE = 65_53669 70- 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 linesmodified:httpx/_decoders.py+1 added-1 removed
243 unmodified lines244 """245 Handles incrementally decoding bytes into text246 """247 248- def __init__(self, encoding: str = "utf-8"):248+ def __init__(self, encoding: str = "utf-8") -> None:249 self.decoder = codecs.getincrementaldecoder(encoding)(errors="replace")250 251 def decode(self, data: bytes) -> str:252 return self.decoder.decode(data)72 unmodified linesmodified:httpx/_models.py+3 added-3 removed
316 unmodified lines317 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 lines455 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)462 463 self._request: typing.Optional[Request] = request736 unmodified lines1200 Wraps a `Request` instance up in a compatibility interface suitable1201 for use with `CookieJar` operations.1202 """1203 1204- def __init__(self, response: Response):1204+ def __init__(self, response: Response) -> None:1205 self.response = response1206 1207 def info(self) -> email.message.Message:1208 info = email.message.Message()6 unmodified linesmodified:tests/client/test_async_client.py+1 added-1 removed
210 unmodified lines211 212 @pytest.mark.anyio213 async 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] = []218 219 async def aclose(self):154 unmodified linesmodified:tests/client/test_auth.py+1 added-1 removed
91 unmodified lines92 """93 94 requires_request_body = True95 96- def __init__(self, repeat: int):96+ def __init__(self, repeat: int) -> None:97 self.repeat = repeat98 99 def auth_flow(100 self, request: httpx.Request693 unmodified linesmodified:tests/client/test_client.py+1 added-1 removed
258 unmodified lines259 260 261 def 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] = []266 267 def close(self):193 unmodified linesmodified:CHANGELOG.md+4 added
4 unmodified lines5 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).6 7 ## Unreleased8 9+### Added10+11+* Add missing type hints to few `__init__()` methods. (#2938)12+13 ## 0.25.1 (3rd November, 2023)14 15 ### Added16 1038 unmodified lines