From ad2ea5b400a501996bb085c7db5a65e7f493e9d0 Mon Sep 17 00:00:00 2001 From: Sarunas Azna Date: Fri, 11 Dec 2020 17:40:50 +0100 Subject: [PATCH 1/6] 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. --- httpx/_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpx/_models.py b/httpx/_models.py index a77f7a5790..94d705d59f 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -441,7 +441,7 @@ def __init__(self, *args: QueryParamTypes, **kwargs: typing.Any) -> None: items = parse_qsl(value) elif isinstance(value, QueryParams): items = value.multi_items() - elif isinstance(value, list): + elif type(value) in [list, tuple]: items = value else: items = flatten_queryparams(value) From 1738b71236f7d4149b1ba8b0f29babfe5862111f Mon Sep 17 00:00:00 2001 From: Sarunas Azna Date: Fri, 11 Dec 2020 17:59:32 +0100 Subject: [PATCH 2/6] tests for two tuples --- tests/models/test_queryparams.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/models/test_queryparams.py b/tests/models/test_queryparams.py index d591eded8c..7031a65cb9 100644 --- a/tests/models/test_queryparams.py +++ b/tests/models/test_queryparams.py @@ -9,6 +9,8 @@ "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): From a76008454b0c565ba1ced86798f6bbe1ef2407dc Mon Sep 17 00:00:00 2001 From: Sarunas Azna Date: Sat, 12 Dec 2020 14:53:51 +0100 Subject: [PATCH 3/6] use isinstance to check the type of query params --- httpx/_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpx/_models.py b/httpx/_models.py index 94d705d59f..2d11888254 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -441,7 +441,7 @@ def __init__(self, *args: QueryParamTypes, **kwargs: typing.Any) -> None: items = parse_qsl(value) elif isinstance(value, QueryParams): items = value.multi_items() - elif type(value) in [list, tuple]: + elif isinstance(value, (list, tuple)): items = value else: items = flatten_queryparams(value) From e50cc55fb8de124f90a92c5f0a34bad8d913cb1b Mon Sep 17 00:00:00 2001 From: Sarunas Azna Date: Sat, 12 Dec 2020 15:42:07 +0100 Subject: [PATCH 4/6] change list|tuple to in Sequence --- httpx/_models.py | 2 +- httpx/_types.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/httpx/_models.py b/httpx/_models.py index 2d11888254..866cfbab66 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -441,7 +441,7 @@ def __init__(self, *args: QueryParamTypes, **kwargs: typing.Any) -> None: items = parse_qsl(value) elif isinstance(value, QueryParams): items = value.multi_items() - elif isinstance(value, (list, tuple)): + elif isinstance(value, typing.Sequence): items = value else: items = flatten_queryparams(value) diff --git a/httpx/_types.py b/httpx/_types.py index 776df1d8dc..33691af2ce 100644 --- a/httpx/_types.py +++ b/httpx/_types.py @@ -34,7 +34,7 @@ QueryParamTypes = Union[ "QueryParams", Mapping[str, Union[PrimitiveData, Sequence[PrimitiveData]]], - List[Tuple[str, PrimitiveData]], + Sequence[Tuple[str, PrimitiveData]], str, bytes, None, From 81ad642fdbfb6292f04c4de25cbed77ca62f7310 Mon Sep 17 00:00:00 2001 From: Sarunas Azna Date: Sat, 12 Dec 2020 15:56:57 +0100 Subject: [PATCH 5/6] update documentation --- httpx/_api.py | 2 +- httpx/_client.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/httpx/_api.py b/httpx/_api.py index 985e2ab938..8cfaf6dfda 100644 --- a/httpx/_api.py +++ b/httpx/_api.py @@ -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, diff --git a/httpx/_client.py b/httpx/_client.py index 0ae5f2b1fa..4f457c79dc 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -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 From 399a669df327f53b8bd7475e57a98e66c09d392e Mon Sep 17 00:00:00 2001 From: Sarunas Azna Date: Sat, 12 Dec 2020 16:52:31 +0100 Subject: [PATCH 6/6] fix typing --- httpx/_models.py | 2 +- httpx/_types.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/httpx/_models.py b/httpx/_models.py index 866cfbab66..2d11888254 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -441,7 +441,7 @@ def __init__(self, *args: QueryParamTypes, **kwargs: typing.Any) -> None: items = parse_qsl(value) elif isinstance(value, QueryParams): items = value.multi_items() - elif isinstance(value, typing.Sequence): + elif isinstance(value, (list, tuple)): items = value else: items = flatten_queryparams(value) diff --git a/httpx/_types.py b/httpx/_types.py index 33691af2ce..7768bac11b 100644 --- a/httpx/_types.py +++ b/httpx/_types.py @@ -34,7 +34,8 @@ QueryParamTypes = Union[ "QueryParams", Mapping[str, Union[PrimitiveData, Sequence[PrimitiveData]]], - Sequence[Tuple[str, PrimitiveData]], + List[Tuple[str, PrimitiveData]], + Tuple[Tuple[str, PrimitiveData], ...], str, bytes, None,