Skip to content

Commit ffbacb0

Browse files
authored
fix: annotate context managers with Generator for ty 0.0.85 (#160)
1 parent 44cb78d commit ffbacb0

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎src/httpware/_internal/exception_mapping.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99

1010
import contextlib
11-
from collections.abc import AsyncIterator, Iterator
11+
from collections.abc import AsyncGenerator, Generator
1212

1313
import httpx2
1414

@@ -33,7 +33,7 @@ def map_httpx2_exception(exc: BaseException) -> NetworkError | TimeoutError | Tr
3333

3434

3535
@contextlib.asynccontextmanager
36-
async def _httpx2_exception_mapper() -> AsyncIterator[None]:
36+
async def _httpx2_exception_mapper() -> AsyncGenerator[None]:
3737
"""Map httpx2 exceptions to httpware exceptions. Shared by AsyncClient._terminal and stream()."""
3838
try:
3939
yield
@@ -44,7 +44,7 @@ async def _httpx2_exception_mapper() -> AsyncIterator[None]:
4444

4545

4646
@contextlib.contextmanager
47-
def _httpx2_exception_mapper_sync() -> Iterator[None]:
47+
def _httpx2_exception_mapper_sync() -> Generator[None]:
4848
"""Map httpx2 exceptions to httpware exceptions. Sync sibling of _httpx2_exception_mapper."""
4949
try:
5050
yield

‎src/httpware/client.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import contextlib
44
import ssl
55
import typing
6-
from collections.abc import AsyncIterator, Callable, Iterator, Mapping, Sequence
6+
from collections.abc import AsyncGenerator, Callable, Generator, Mapping, Sequence
77
from http import HTTPStatus
88

99
import httpx2
@@ -205,7 +205,7 @@ async def _send_capped_async(client: httpx2.AsyncClient, request: httpx2.Request
205205
@contextlib.asynccontextmanager
206206
async def _stream_async(
207207
client: httpx2.AsyncClient, method: str, url: httpx2.URL | str, kwargs: dict[str, typing.Any]
208-
) -> AsyncIterator[httpx2.Response]:
208+
) -> AsyncGenerator[httpx2.Response]:
209209
"""Mirror of `httpx2.AsyncClient.stream` that builds via `_build_request`."""
210210
response = await client.send(_build_request(client, method, url, kwargs), stream=True)
211211
try:
@@ -221,7 +221,7 @@ async def _stream_capped_async(
221221
url: httpx2.URL | str,
222222
kwargs: dict[str, typing.Any],
223223
cap: int,
224-
) -> AsyncIterator[httpx2.Response]:
224+
) -> AsyncGenerator[httpx2.Response]:
225225
"""Async mirror of `httpx2.AsyncClient.stream` that sends via `_send_capped_async`."""
226226
response = await _send_capped_async(client, _build_request(client, method, url, kwargs), cap)
227227
try:
@@ -286,7 +286,7 @@ def _send_capped(client: httpx2.Client, request: httpx2.Request, cap: int) -> ht
286286
@contextlib.contextmanager
287287
def _stream(
288288
client: httpx2.Client, method: str, url: httpx2.URL | str, kwargs: dict[str, typing.Any]
289-
) -> Iterator[httpx2.Response]:
289+
) -> Generator[httpx2.Response]:
290290
"""Sync mirror of `_stream_async`."""
291291
response = client.send(_build_request(client, method, url, kwargs), stream=True)
292292
try:
@@ -302,7 +302,7 @@ def _stream_capped(
302302
url: httpx2.URL | str,
303303
kwargs: dict[str, typing.Any],
304304
cap: int,
305-
) -> Iterator[httpx2.Response]:
305+
) -> Generator[httpx2.Response]:
306306
"""Sync mirror of `_stream_capped_async`."""
307307
response = _send_capped(client, _build_request(client, method, url, kwargs), cap)
308308
try:
@@ -1221,7 +1221,7 @@ async def stream( # noqa: PLR0913 — mirrors httpx2 per-method signatures; kwa
12211221
content: typing.Any | None = None,
12221222
data: typing.Any | None = None,
12231223
files: typing.Any | None = None,
1224-
) -> AsyncIterator[httpx2.Response]:
1224+
) -> AsyncGenerator[httpx2.Response]:
12251225
"""Stream an HTTP response. Bypasses the middleware chain.
12261226
12271227
Yields an httpx2.Response; consume the body via response.aiter_bytes(),
@@ -2180,7 +2180,7 @@ def stream( # noqa: PLR0913 — mirrors httpx2 per-method signatures; kwargs-fo
21802180
content: typing.Any | None = None,
21812181
data: typing.Any | None = None,
21822182
files: typing.Any | None = None,
2183-
) -> Iterator[httpx2.Response]:
2183+
) -> Generator[httpx2.Response]:
21842184
"""Stream an HTTP response. Bypasses the middleware chain.
21852185
21862186
Yields an httpx2.Response; consume the body via response.iter_bytes(),

‎tests/test_client_dispatch.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import contextlib
88
import dataclasses
9-
from collections.abc import Iterator
9+
from collections.abc import Generator
1010
from http import HTTPStatus
1111
from unittest.mock import MagicMock, patch
1212

@@ -59,7 +59,7 @@ def handler(request: httpx2.Request) -> httpx2.Response:
5959

6060

6161
@contextlib.contextmanager
62-
def _decode_spies(*decoders: ResponseDecoder) -> Iterator[list[MagicMock]]:
62+
def _decode_spies(*decoders: ResponseDecoder) -> Generator[list[MagicMock]]:
6363
"""Wrap each decoder's `decode` so a test can assert WHICH one ran.
6464
6565
Two real decoders that both claim a shared shape (e.g. `dict[str, int]` or a

0 commit comments

Comments
 (0)