Skip to content

Commit b4d8f9a

Browse files
authored
fix: add overloads to AsyncSession.send() for stream-dependent return type (#335)
## Summary `AsyncSession.send()` returns `Response | AsyncResponse` without narrowing based on the `stream` parameter, unlike `request()`, `get()`, `post()`, and other public methods which already have `@overload` stubs. ## Fix Adds `@typing.overload` stubs to `AsyncSession.send()` so the return type is narrowed based on `stream`: - `stream=True` → `AsyncResponse` - default → `Response`
1 parent 631baf1 commit b4d8f9a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/niquests/async_session.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,12 @@ def get_adapter(self, url: str) -> AsyncBaseAdapter: # type: ignore[override]
450450
# Nothing matches :-/
451451
raise InvalidSchema(f"No connection adapters were found for {url!r}{additional_hint}")
452452

453+
@typing.overload # type: ignore[override]
454+
async def send(self, request: PreparedRequest, *, stream: Literal[True], **kwargs: typing.Any) -> AsyncResponse: ...
455+
456+
@typing.overload # type: ignore[override]
457+
async def send(self, request: PreparedRequest, **kwargs: typing.Any) -> Response: ...
458+
453459
async def send( # type: ignore[override]
454460
self, request: PreparedRequest, **kwargs: typing.Any
455461
) -> Response | AsyncResponse: # type: ignore[override]

0 commit comments

Comments
 (0)