Skip to content

Commit

Permalink
add missing type hints to __init__(...) (#2938)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Nov 17, 2023
1 parent c51e046 commit 87f39f1
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions httpx/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions httpx/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions httpx/_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion httpx/_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions httpx/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions httpx/_transports/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion tests/client/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []

Expand Down
2 changes: 1 addition & 1 deletion tests/client/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []

Expand Down

0 comments on commit 87f39f1

Please sign in to comment.