Skip to content
Myr

Allow tuple as input of query parameters. (#1426)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* 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

authored by SarunasAzna · committed by GitHub · parent 584a405 · Browse files · 5 files+7 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+7 added−4 removed

  • tests:+2 added−0 removed
  • other:+5 added−4 removed

5 files+7 added−4 removed

modified:httpx/_api.py+1 added-1 removed
45 unmodified lines
46 * **method** - HTTP method for the new `Request` object: `GET`, `OPTIONS`,47 `HEAD`, `POST`, `PUT`, `PATCH`, or `DELETE`.48 * **url** - URL for the new `Request` object.49 * **params** - *(optional)* Query parameters to include in the URL, as a50 string, dictionary, or list of two-tuples.50 string, dictionary, or sequence of two-tuples.51 * **content** - *(optional)* Binary content to include in the body of the52 request, as bytes or a byte iterator.53 * **data** - *(optional)* Form data to include in the body of the request,54 as a dictionary.
383 unmodified lines
modified:httpx/_client.py+2 added-2 removed
518 unmodified lines
519520 * **auth** - *(optional)* An authentication class to use when sending521 requests.522 * **params** - *(optional)* Query parameters to include in request URLs, as523 a string, dictionary, or list of two-tuples.523 a string, dictionary, or sequence of two-tuples.524 * **headers** - *(optional)* Dictionary of HTTP headers to include when525 sending requests.526 * **cookies** - *(optional)* Dictionary of Cookie items to include when527 sending requests.
632 unmodified lines
11601161 * **auth** - *(optional)* An authentication class to use when sending1162 requests.1163 * **params** - *(optional)* Query parameters to include in request URLs, as1164 a string, dictionary, or list of two-tuples.1164 a string, dictionary, or sequence of two-tuples.1165 * **headers** - *(optional)* Dictionary of HTTP headers to include when1166 sending requests.1167 * **cookies** - *(optional)* Dictionary of Cookie items to include when1168 sending requests.
688 unmodified lines
modified:httpx/_models.py+1 added-1 removed
439 unmodified lines
440 value = value.decode("ascii") if isinstance(value, bytes) else value441 items = parse_qsl(value)442 elif isinstance(value, QueryParams):443 items = value.multi_items()444 elif isinstance(value, list):444 elif isinstance(value, (list, tuple)):445 items = value446 else:447 items = flatten_queryparams(value)448
1090 unmodified lines
modified:httpx/_types.py+1 added
33 unmodified lines
34QueryParamTypes = Union[35 "QueryParams",36 Mapping[str, Union[PrimitiveData, Sequence[PrimitiveData]]],37 List[Tuple[str, PrimitiveData]],38 Tuple[Tuple[str, PrimitiveData], ...],39 str,40 bytes,41 None,42]
43 unmodified lines
modified:tests/models/test_queryparams.py+2 added
7 unmodified lines
8 [9 "a=123&a=456&b=789",10 {"a": ["123", "456"], "b": 789},11 {"a": ("123", "456"), "b": 789},12 [("a", "123"), ("a", "456"), ("b", "789")],13 (("a", "123"), ("a", "456"), ("b", "789")),14 ],15)16def test_queryparams(source):17 q = httpx.QueryParams(source)
77 unmodified lines