Skip to content

Commit

Permalink
Allow tuple as input of query parameters. (#1426)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SarunasAzna committed Dec 12, 2020
1 parent 584a405 commit 8696405
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion httpx/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion httpx/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 isinstance(value, (list, tuple)):
items = value
else:
items = flatten_queryparams(value)
Expand Down
1 change: 1 addition & 0 deletions httpx/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"QueryParams",
Mapping[str, Union[PrimitiveData, Sequence[PrimitiveData]]],
List[Tuple[str, PrimitiveData]],
Tuple[Tuple[str, PrimitiveData], ...],
str,
bytes,
None,
Expand Down
2 changes: 2 additions & 0 deletions tests/models/test_queryparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 8696405

Please sign in to comment.