From bccab1dc7f0eaed06b7881006d8d36c714466bca Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 6 Jan 2022 14:33:35 +0000 Subject: [PATCH 1/2] Version 0.21.3 --- CHANGELOG.md | 6 ++++++ httpx/__version__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9230601625..d7d8020aab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## 0.21.3 (6th January, 2022) + +### Fixed + +* Fix streaming uploads using `SyncByteStream` or `AsyncByteStream`. Regression in 0.12.2. (#2016) + ## 0.21.2 (5th January, 2022) ### Fixed diff --git a/httpx/__version__.py b/httpx/__version__.py index 4b45451cea..70decd1bbe 100644 --- a/httpx/__version__.py +++ b/httpx/__version__.py @@ -1,3 +1,3 @@ __title__ = "httpx" __description__ = "A next generation HTTP client, for Python 3." -__version__ = "0.21.2" +__version__ = "0.21.3" From 4cb242e57ad4362762e3001df8cf4f18f27f5c86 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 12 Jan 2022 11:49:16 +0000 Subject: [PATCH 2/2] Don't perform implict close on __del__ --- httpx/_client.py | 38 ------------------------------- tests/client/test_async_client.py | 8 ------- 2 files changed, 46 deletions(-) diff --git a/httpx/_client.py b/httpx/_client.py index 5621520377..2b513b0d35 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -1273,13 +1273,6 @@ def __exit__( if transport is not None: transport.__exit__(exc_type, exc_value, traceback) - def __del__(self) -> None: - # We use 'getattr' here, to manage the case where '__del__()' is called - # on a partially initiallized instance that raised an exception during - # the call to '__init__()'. - if getattr(self, "_state", None) == ClientState.OPENED: # noqa: B009 - self.close() - class AsyncClient(BaseClient): """ @@ -1983,34 +1976,3 @@ async def __aexit__( for proxy in self._mounts.values(): if proxy is not None: await proxy.__aexit__(exc_type, exc_value, traceback) - - def __del__(self) -> None: - # We use 'getattr' here, to manage the case where '__del__()' is called - # on a partially initiallized instance that raised an exception during - # the call to '__init__()'. - if getattr(self, "_state", None) == ClientState.OPENED: # noqa: B009 - # Unlike the sync case, we cannot silently close the client when - # it is garbage collected, because `.aclose()` is an async operation, - # but `__del__` is not. - # - # For this reason we require explicit close management for - # `AsyncClient`, and issue a warning on unclosed clients. - # - # The context managed style is usually preferable, because it neatly - # ensures proper resource cleanup: - # - # async with httpx.AsyncClient() as client: - # ... - # - # However, an explicit call to `aclose()` is also sufficient: - # - # client = httpx.AsyncClient() - # try: - # ... - # finally: - # await client.aclose() - warnings.warn( - f"Unclosed {self!r}. " - "See https://www.python-httpx.org/async/#opening-and-closing-clients " - "for details." - ) diff --git a/tests/client/test_async_client.py b/tests/client/test_async_client.py index 1761287454..219d612f79 100644 --- a/tests/client/test_async_client.py +++ b/tests/client/test_async_client.py @@ -286,14 +286,6 @@ async def test_client_closed_state_using_with_block(): await client.get("http://example.com") -@pytest.mark.usefixtures("async_environment") -async def test_deleting_unclosed_async_client_causes_warning(): - client = httpx.AsyncClient(transport=httpx.MockTransport(hello_world)) - await client.get("http://example.com") - with pytest.warns(UserWarning): - del client - - def unmounted(request: httpx.Request) -> httpx.Response: data = {"app": "unmounted"} return httpx.Response(200, json=data)