From 0493806a3a50da6707e78044c2fcefc5e383efbc Mon Sep 17 00:00:00 2001 From: Bakyt Niiazaliev Date: Fri, 13 Jun 2025 20:35:42 +0700 Subject: [PATCH] fix: register QueryParams as Mapping for isinstance check --- python/httpx/_urls.py | 6 ++++++ tests/client/test_queryparams.py | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/python/httpx/_urls.py b/python/httpx/_urls.py index 265403a7..711bd33d 100644 --- a/python/httpx/_urls.py +++ b/python/httpx/_urls.py @@ -12,6 +12,12 @@ from ._urlparse import urlparse __all__ = ["URL", "QueryParams"] +if not typing.TYPE_CHECKING: + from collections.abc import Mapping + + Mapping.register(QueryParams) + + class URL: """ url = httpx.URL("HTTPS://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink") diff --git a/tests/client/test_queryparams.py b/tests/client/test_queryparams.py index e5acb0ba..49c30d9b 100644 --- a/tests/client/test_queryparams.py +++ b/tests/client/test_queryparams.py @@ -1,3 +1,5 @@ +import typing + import httpx @@ -5,6 +7,13 @@ def hello_world(request: httpx.Request) -> httpx.Response: return httpx.Response(200, text="Hello, world") +def test_queryparams_isinstance_of_mapping(): + client = httpx.Client(params={"a": "b"}) + assert isinstance(client.params, httpx.QueryParams) + assert isinstance(client.params, typing.Mapping) + assert client.params["a"] == "b" + + def test_client_queryparams(): client = httpx.Client(params={"a": "b"}) assert isinstance(client.params, httpx.QueryParams)