Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/httpware/_internal/exception_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

import contextlib
from collections.abc import AsyncIterator, Iterator
from collections.abc import AsyncGenerator, Generator

import httpx2

Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/httpware/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_client_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading