]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Allow tuple as input of query parameters. (#1426)
authorSarunasAzna <SarunasAzna@users.noreply.github.com>
Sat, 12 Dec 2020 17:38:37 +0000 (18:38 +0100)
committerGitHub <noreply@github.com>
Sat, 12 Dec 2020 17:38:37 +0000 (18:38 +0100)
* Allow tuple as input of query parameters.

In the documentation it is stated that params can be dict, string or two
tuples. This allows to used two tuples. Previously it was possible to
use only tuple inside a list.

* tests for two tuples

* use isinstance to check the type of query params

* change list|tuple to in Sequence

* update documentation

* fix typing

httpx/_api.py
httpx/_client.py
httpx/_models.py
httpx/_types.py
tests/models/test_queryparams.py

index 985e2ab93866062a6d049576fb0627675012b5df..8cfaf6dfda3269c007837e71a1f35b2f1cc6a6c7 100644 (file)
@@ -47,7 +47,7 @@ def request(
     `HEAD`, `POST`, `PUT`, `PATCH`, or `DELETE`.
     * **url** - URL for the new `Request` object.
     * **params** - *(optional)* Query parameters to include in the URL, as a
-    string, dictionary, or list of two-tuples.
+    string, dictionary, or sequence of two-tuples.
     * **content** - *(optional)* Binary content to include in the body of the
     request, as bytes or a byte iterator.
     * **data** - *(optional)* Form data to include in the body of the request,
index 0ae5f2b1facfcda55b9124d53a4c6d7d09395a5a..4f457c79dcf5d36c4d72a23d400d3e7439637bd8 100644 (file)
@@ -520,7 +520,7 @@ class Client(BaseClient):
     * **auth** - *(optional)* An authentication class to use when sending
     requests.
     * **params** - *(optional)* Query parameters to include in request URLs, as
-    a string, dictionary, or list of two-tuples.
+    a string, dictionary, or sequence of two-tuples.
     * **headers** - *(optional)* Dictionary of HTTP headers to include when
     sending requests.
     * **cookies** - *(optional)* Dictionary of Cookie items to include when
@@ -1161,7 +1161,7 @@ class AsyncClient(BaseClient):
     * **auth** - *(optional)* An authentication class to use when sending
     requests.
     * **params** - *(optional)* Query parameters to include in request URLs, as
-    a string, dictionary, or list of two-tuples.
+    a string, dictionary, or sequence of two-tuples.
     * **headers** - *(optional)* Dictionary of HTTP headers to include when
     sending requests.
     * **cookies** - *(optional)* Dictionary of Cookie items to include when
index a77f7a57904d354957bd1ae5ec2a11acecaa2ca0..2d11888254a03491d646c9ce07cec60502f1f59d 100644 (file)
@@ -441,7 +441,7 @@ class QueryParams(typing.Mapping[str, str]):
             items = parse_qsl(value)
         elif isinstance(value, QueryParams):
             items = value.multi_items()
-        elif isinstance(value, list):
+        elif isinstance(value, (list, tuple)):
             items = value
         else:
             items = flatten_queryparams(value)
index 776df1d8dc9b46313ff87ba204a680425f235466..7768bac11b97c4fe72206f93c71254f2a707be36 100644 (file)
@@ -35,6 +35,7 @@ QueryParamTypes = Union[
     "QueryParams",
     Mapping[str, Union[PrimitiveData, Sequence[PrimitiveData]]],
     List[Tuple[str, PrimitiveData]],
+    Tuple[Tuple[str, PrimitiveData], ...],
     str,
     bytes,
     None,
index d591eded8c33aa5cda24f1870bff4df882679afe..7031a65cb936ebdeb9b980ad6d14f0bf9fd44e4d 100644 (file)
@@ -9,6 +9,8 @@ import httpx
         "a=123&a=456&b=789",
         {"a": ["123", "456"], "b": 789},
         {"a": ("123", "456"), "b": 789},
+        [("a", "123"), ("a", "456"), ("b", "789")],
+        (("a", "123"), ("a", "456"), ("b", "789")),
     ],
 )
 def test_queryparams(source):