diff --git a/src/httpware/_internal/exception_mapping.py b/src/httpware/_internal/exception_mapping.py index 118b652..33be681 100644 --- a/src/httpware/_internal/exception_mapping.py +++ b/src/httpware/_internal/exception_mapping.py @@ -8,7 +8,7 @@ """ import contextlib -from collections.abc import AsyncIterator, Iterator +from collections.abc import AsyncGenerator, Generator import httpx2 @@ -33,7 +33,7 @@ def map_httpx2_exception(exc: BaseException) -> NetworkError | TimeoutError | Tr @contextlib.asynccontextmanager -async def _httpx2_exception_mapper() -> AsyncIterator[None]: +async def _httpx2_exception_mapper() -> AsyncGenerator[None]: """Map httpx2 exceptions to httpware exceptions. Shared by AsyncClient._terminal and stream().""" try: yield @@ -44,7 +44,7 @@ async def _httpx2_exception_mapper() -> AsyncIterator[None]: @contextlib.contextmanager -def _httpx2_exception_mapper_sync() -> Iterator[None]: +def _httpx2_exception_mapper_sync() -> Generator[None]: """Map httpx2 exceptions to httpware exceptions. Sync sibling of _httpx2_exception_mapper.""" try: yield diff --git a/src/httpware/client.py b/src/httpware/client.py index 5a22d37..65ff7d3 100644 --- a/src/httpware/client.py +++ b/src/httpware/client.py @@ -3,7 +3,7 @@ import contextlib import ssl import typing -from collections.abc import AsyncIterator, Callable, Iterator, Mapping, Sequence +from collections.abc import AsyncGenerator, Callable, Generator, Mapping, Sequence from http import HTTPStatus import httpx2 @@ -205,7 +205,7 @@ async def _send_capped_async(client: httpx2.AsyncClient, request: httpx2.Request @contextlib.asynccontextmanager async def _stream_async( client: httpx2.AsyncClient, method: str, url: httpx2.URL | str, kwargs: dict[str, typing.Any] -) -> AsyncIterator[httpx2.Response]: +) -> AsyncGenerator[httpx2.Response]: """Mirror of `httpx2.AsyncClient.stream` that builds via `_build_request`.""" response = await client.send(_build_request(client, method, url, kwargs), stream=True) try: @@ -221,7 +221,7 @@ async def _stream_capped_async( url: httpx2.URL | str, kwargs: dict[str, typing.Any], cap: int, -) -> AsyncIterator[httpx2.Response]: +) -> AsyncGenerator[httpx2.Response]: """Async mirror of `httpx2.AsyncClient.stream` that sends via `_send_capped_async`.""" response = await _send_capped_async(client, _build_request(client, method, url, kwargs), cap) try: @@ -286,7 +286,7 @@ def _send_capped(client: httpx2.Client, request: httpx2.Request, cap: int) -> ht @contextlib.contextmanager def _stream( client: httpx2.Client, method: str, url: httpx2.URL | str, kwargs: dict[str, typing.Any] -) -> Iterator[httpx2.Response]: +) -> Generator[httpx2.Response]: """Sync mirror of `_stream_async`.""" response = client.send(_build_request(client, method, url, kwargs), stream=True) try: @@ -302,7 +302,7 @@ def _stream_capped( url: httpx2.URL | str, kwargs: dict[str, typing.Any], cap: int, -) -> Iterator[httpx2.Response]: +) -> Generator[httpx2.Response]: """Sync mirror of `_stream_capped_async`.""" response = _send_capped(client, _build_request(client, method, url, kwargs), cap) try: @@ -1221,7 +1221,7 @@ async def stream( # noqa: PLR0913 — mirrors httpx2 per-method signatures; kwa content: typing.Any | None = None, data: typing.Any | None = None, files: typing.Any | None = None, - ) -> AsyncIterator[httpx2.Response]: + ) -> AsyncGenerator[httpx2.Response]: """Stream an HTTP response. Bypasses the middleware chain. 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 content: typing.Any | None = None, data: typing.Any | None = None, files: typing.Any | None = None, - ) -> Iterator[httpx2.Response]: + ) -> Generator[httpx2.Response]: """Stream an HTTP response. Bypasses the middleware chain. Yields an httpx2.Response; consume the body via response.iter_bytes(), diff --git a/tests/test_client_dispatch.py b/tests/test_client_dispatch.py index b46dd47..1407e1f 100644 --- a/tests/test_client_dispatch.py +++ b/tests/test_client_dispatch.py @@ -6,7 +6,7 @@ import contextlib import dataclasses -from collections.abc import Iterator +from collections.abc import Generator from http import HTTPStatus from unittest.mock import MagicMock, patch @@ -59,7 +59,7 @@ def handler(request: httpx2.Request) -> httpx2.Response: @contextlib.contextmanager -def _decode_spies(*decoders: ResponseDecoder) -> Iterator[list[MagicMock]]: +def _decode_spies(*decoders: ResponseDecoder) -> Generator[list[MagicMock]]: """Wrap each decoder's `decode` so a test can assert WHICH one ran. Two real decoders that both claim a shared shape (e.g. `dict[str, int]` or a