From ff93a011a44f4a76015e4866d01ff79a6afe350a Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 16 Jul 2020 11:16:29 +0100 Subject: [PATCH] Support QueryParams(None) (#1060) --- httpx/_client.py | 3 --- httpx/_models.py | 2 +- httpx/_types.py | 1 + tests/models/test_queryparams.py | 3 +++ 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/httpx/_client.py b/httpx/_client.py index 35d0bd0fe5..80a2bb03c3 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -73,9 +73,6 @@ def __init__( else: self.base_url = URL(base_url) - if params is None: - params = {} - self.auth = auth self._params = QueryParams(params) self._headers = Headers(headers) diff --git a/httpx/_models.py b/httpx/_models.py index bf5f6d1cdd..1ab162cd65 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -287,7 +287,7 @@ def __init__(self, *args: QueryParamTypes, **kwargs: typing.Any) -> None: value = args[0] if args else kwargs items: typing.Sequence[typing.Tuple[str, PrimitiveData]] - if isinstance(value, str): + if value is None or isinstance(value, str): items = parse_qsl(value) elif isinstance(value, QueryParams): items = value.multi_items() diff --git a/httpx/_types.py b/httpx/_types.py index d2fc098e24..bfce5650da 100644 --- a/httpx/_types.py +++ b/httpx/_types.py @@ -34,6 +34,7 @@ Mapping[str, Union[PrimitiveData, Sequence[PrimitiveData]]], List[Tuple[str, PrimitiveData]], str, + None, ] HeaderTypes = Union[ diff --git a/tests/models/test_queryparams.py b/tests/models/test_queryparams.py index 0b0101cb31..99f193f86d 100644 --- a/tests/models/test_queryparams.py +++ b/tests/models/test_queryparams.py @@ -44,6 +44,9 @@ def test_queryparams(source): def test_queryparam_types(): + q = QueryParams(None) + assert str(q) == "" + q = QueryParams({"a": True}) assert str(q) == "a=true"