diff --git a/httpx/_client.py b/httpx/_client.py index 2249231f8c..6131f14df9 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -281,7 +281,7 @@ def auth(self) -> Auth | None: return self._auth @auth.setter - def auth(self, auth: AuthTypes) -> None: + def auth(self, auth: AuthTypes | None) -> None: self._auth = self._build_auth(auth) @property diff --git a/tests/client/test_auth.py b/tests/client/test_auth.py index 7638b8bd68..5c5665f080 100644 --- a/tests/client/test_auth.py +++ b/tests/client/test_auth.py @@ -335,6 +335,24 @@ async def test_auth_property() -> None: assert response.json() == {"auth": "Basic dXNlcjpwYXNzd29yZDEyMw=="} +@pytest.mark.anyio +async def test_auth_property_none() -> None: + app = App() + + async with httpx.AsyncClient( + transport=httpx.MockTransport(app), auth=("user", "password123") + ) as client: + assert isinstance(client.auth, httpx.BasicAuth) + + client.auth = None + assert client.auth is None + + url = "https://example.org/" + response = await client.get(url) + assert response.status_code == 200 + assert response.json() == {"auth": None} + + @pytest.mark.anyio async def test_auth_invalid_type() -> None: app = App()