From 042f2d19adbf7d46c222fe2cd157f6035af0dc48 Mon Sep 17 00:00:00 2001 From: karpetrosyan Date: Sun, 3 Mar 2024 04:13:38 -0500 Subject: [PATCH 1/5] Ensure starlette fails with httpx use-unasync branch --- pyproject.toml | 1 - requirements.txt | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 679deaade..ea63e8326 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,6 @@ full = [ "jinja2", "python-multipart>=0.0.7", "pyyaml", - "httpx>=0.22.0", ] [project.urls] diff --git a/requirements.txt b/requirements.txt index 5652a865e..e781d4b2f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,3 +21,6 @@ mkautodoc==0.2.0 # Packaging build==1.1.1 twine==5.0.0 + +# httpx test +httpx @ git+https://github.com/encode/httpx@use-unasync From dd80860ef3abeef5aa49685fe6a0b92e7c7e986f Mon Sep 17 00:00:00 2001 From: karpetrosyan Date: Sun, 3 Mar 2024 04:20:04 -0500 Subject: [PATCH 2/5] Change imports from httpx._client to httpx._config --- pyproject.toml | 1 + requirements.txt | 3 --- starlette/testclient.py | 38 +++++++++++++++++++------------------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ea63e8326..679deaade 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ full = [ "jinja2", "python-multipart>=0.0.7", "pyyaml", + "httpx>=0.22.0", ] [project.urls] diff --git a/requirements.txt b/requirements.txt index e781d4b2f..5652a865e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,6 +21,3 @@ mkautodoc==0.2.0 # Packaging build==1.1.1 twine==5.0.0 - -# httpx test -httpx @ git+https://github.com/encode/httpx@use-unasync diff --git a/starlette/testclient.py b/starlette/testclient.py index f17d4e892..28c49d382 100644 --- a/starlette/testclient.py +++ b/starlette/testclient.py @@ -472,9 +472,9 @@ def _portal_factory(self) -> typing.Generator[anyio.abc.BlockingPortal, None, No def _choose_redirect_arg( self, follow_redirects: bool | None, allow_redirects: bool | None - ) -> bool | httpx._client.UseClientDefault: - redirect: bool | httpx._client.UseClientDefault = ( - httpx._client.USE_CLIENT_DEFAULT + ) -> bool | httpx._config.UseClientDefault: + redirect: bool | httpx._config.UseClientDefault = ( + httpx._config.USE_CLIENT_DEFAULT ) if allow_redirects is not None: message = ( @@ -504,11 +504,11 @@ def request( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: url = self._merge_url(url) @@ -537,11 +537,11 @@ def get( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -564,11 +564,11 @@ def options( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -591,11 +591,11 @@ def head( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -622,11 +622,11 @@ def post( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -657,11 +657,11 @@ def put( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -692,11 +692,11 @@ def patch( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -723,11 +723,11 @@ def delete( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) From 721e64f9836b550d2dd5afc4991898d69280fbd2 Mon Sep 17 00:00:00 2001 From: karpetrosyan Date: Sun, 3 Mar 2024 04:22:49 -0500 Subject: [PATCH 3/5] Install httpx from the branch, to ensure that it will work --- pyproject.toml | 1 - requirements.txt | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 679deaade..ea63e8326 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,6 @@ full = [ "jinja2", "python-multipart>=0.0.7", "pyyaml", - "httpx>=0.22.0", ] [project.urls] diff --git a/requirements.txt b/requirements.txt index 5652a865e..e781d4b2f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,3 +21,6 @@ mkautodoc==0.2.0 # Packaging build==1.1.1 twine==5.0.0 + +# httpx test +httpx @ git+https://github.com/encode/httpx@use-unasync From 617e002eda4916d07b4eaeb81fcc2b8953103419 Mon Sep 17 00:00:00 2001 From: karpetrosyan Date: Sun, 3 Mar 2024 04:30:53 -0500 Subject: [PATCH 4/5] Import USE_CLIENT_DEFAULT from the public api rather from private --- starlette/testclient.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/starlette/testclient.py b/starlette/testclient.py index 28c49d382..467553df4 100644 --- a/starlette/testclient.py +++ b/starlette/testclient.py @@ -473,9 +473,7 @@ def _portal_factory(self) -> typing.Generator[anyio.abc.BlockingPortal, None, No def _choose_redirect_arg( self, follow_redirects: bool | None, allow_redirects: bool | None ) -> bool | httpx._config.UseClientDefault: - redirect: bool | httpx._config.UseClientDefault = ( - httpx._config.USE_CLIENT_DEFAULT - ) + redirect: bool | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT if allow_redirects is not None: message = ( "The `allow_redirects` argument is deprecated. " @@ -504,11 +502,11 @@ def request( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: url = self._merge_url(url) @@ -537,11 +535,11 @@ def get( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -564,11 +562,11 @@ def options( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -591,11 +589,11 @@ def head( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -622,11 +620,11 @@ def post( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -657,11 +655,11 @@ def put( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -692,11 +690,11 @@ def patch( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) @@ -723,11 +721,11 @@ def delete( # type: ignore[override] headers: httpx._types.HeaderTypes | None = None, cookies: httpx._types.CookieTypes | None = None, auth: httpx._types.AuthTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, follow_redirects: bool | None = None, allow_redirects: bool | None = None, timeout: httpx._types.TimeoutTypes - | httpx._config.UseClientDefault = httpx._config.USE_CLIENT_DEFAULT, + | httpx._config.UseClientDefault = httpx.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: redirect = self._choose_redirect_arg(follow_redirects, allow_redirects) From a1d5f2d49f65e3c6af51f2135e9987590dedc93e Mon Sep 17 00:00:00 2001 From: karpetrosyan Date: Sun, 3 Mar 2024 04:32:15 -0500 Subject: [PATCH 5/5] Revert "Install httpx from the branch, to ensure that it will work" This reverts commit 721e64f9836b550d2dd5afc4991898d69280fbd2. --- pyproject.toml | 1 + requirements.txt | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ea63e8326..679deaade 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ full = [ "jinja2", "python-multipart>=0.0.7", "pyyaml", + "httpx>=0.22.0", ] [project.urls] diff --git a/requirements.txt b/requirements.txt index e781d4b2f..5652a865e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,6 +21,3 @@ mkautodoc==0.2.0 # Packaging build==1.1.1 twine==5.0.0 - -# httpx test -httpx @ git+https://github.com/encode/httpx@use-unasync