Skip to content
Myr

Preserve list type query paramaters when merging QueryParams objects (#546) (#547)

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

authored by Casey · committed by Tom Christie · parent 095b691 · Browse files · 2 files+16 added−1 removed
This commit

State

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

Diff stats

2 files+16 added−1 removed

  • tests:+10 added−0 removed
  • other:+6 added−1 removed

2 files+16 added−1 removed

modified:httpx/models.py+6 added-1 removed
343 unmodified lines
344 return345346 params = QueryParams(params)347 for param in params:348 item, *extras = params.getlist(param)349 self[param] = item350 if extras:351 self._list.extend((param, e) for e in extras)352 # ensure getter matches merged QueryParams getter348 self[param] = params[param]353 self._dict[param] = params[param]354355 def __getitem__(self, key: typing.Any) -> str:356 return self._dict[key]357
789 unmodified lines
modified:tests/models/test_queryparams.py+10 added
60 unmodified lines
6162 q = QueryParams({"a": 123})63 assert str(q) == "a=123"6465 q = QueryParams({"a": [1, 2]})66 assert str(q) == "a=1&a=2"676869def test_queryparam_setters():70 q = QueryParams({"a": 1})71 q.update([])72
1 unmodified line
7475 q = QueryParams([("a", 1), ("a", 2)])76 q["a"] = "3"77 assert str(q) == "a=3"7879 q = QueryParams([("a", 1), ("b", 1)])80 u = QueryParams([("b", 2), ("b", 3)])81 q.update(u)8283 assert str(q) == "a=1&b=2&b=3"84 assert q["b"] == u["b"]