From 4f19090814caff063e7af361fd1e65c41a6cfefa Mon Sep 17 00:00:00 2001 From: TAHRI Ahmed R Date: Thu, 18 Jan 2024 21:36:30 +0100 Subject: [PATCH] :sparkle: Add awaitable close method within AsyncSession (#70) --- HISTORY.md | 4 ++++ src/niquests/__version__.py | 4 ++-- src/niquests/_async.py | 10 +++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 938ca7cb4a..d30c5ddb5c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,6 +7,10 @@ Release History **Fixed** - Issuing a request with `Session(multiplexed=True)` that weren't eligible (e.g. HTTP/1.1) but was redirected to an eligible server (HTTP/2+) caused a rare error. +- An anonymous netrc entry (e.g. username only) could be wrongfully used when it should be discarded. (PR #61) + +**Added** +- Awaitable close method within `AsyncSession`. 3.4.3 (2024-01-16) ------------------ diff --git a/src/niquests/__version__.py b/src/niquests/__version__.py index 6299acb2a2..dde66d8110 100644 --- a/src/niquests/__version__.py +++ b/src/niquests/__version__.py @@ -9,9 +9,9 @@ __url__: str = "https://niquests.readthedocs.io" __version__: str -__version__ = "3.4.3" +__version__ = "3.4.4" -__build__: int = 0x030403 +__build__: int = 0x030404 __author__: str = "Kenneth Reitz" __author_email__: str = "me@kennethreitz.org" __license__: str = "Apache-2.0" diff --git a/src/niquests/_async.py b/src/niquests/_async.py index 1cc2f2f736..c8d596b82a 100644 --- a/src/niquests/_async.py +++ b/src/niquests/_async.py @@ -68,9 +68,7 @@ async def __aenter__(self): return self async def __aexit__(self, exc, value, tb): - await sync_to_async( - super().__exit__, thread_sensitive=AsyncSession.disable_thread - )() + await self.close() async def send( # type: ignore[override] self, request: PreparedRequest, **kwargs: typing.Any @@ -718,6 +716,12 @@ async def gather(self, *responses: Response, max_fetch: int | None = None) -> No thread_sensitive=AsyncSession.disable_thread, )(*responses, max_fetch=max_fetch) + async def close(self) -> None: # type: ignore[override] + await sync_to_async( + super().close, + thread_sensitive=AsyncSession.disable_thread, + )() + class AsyncResponse(Response): def __aenter__(self) -> AsyncResponse: