Use get_list consistently (#1119)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Use get_list consistently * Ensure DeprecationWarning on getlist vs. get_list
authored by Tom Christie · committed by GitHub · parent d76b2c2 · Browse files · 3 files·+12 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
3 files+12 added−4 removed
- tests:+8 added−0 removed
- other:+4 added−4 removed
Provenance
- Commit
e5f8743- Tree
0105efc- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
d76b2c2
3 files changed+12 added−4 removed
modified:httpx/_models.py+4 added-4 removed
279 unmodified lines280 return281 282 params = QueryParams(params)283 for param in params:284- item, *extras = params.getlist(param)284+ item, *extras = params.get_list(param)285 self[param] = item286 if extras:287 self._list.extend((param, e) for e in extras)288 # ensure getter matches merged QueryParams getter44 unmodified lines333 def getlist(self, key: typing.Any) -> typing.List[str]:334 message = (335 "QueryParams.getlist() is pending deprecation. Use QueryParams.get_list()"336 )337- warnings.warn(message, PendingDeprecationWarning)337+ warnings.warn(message, DeprecationWarning)338 return self.get_list(key)339 340 341 class Headers(typing.MutableMapping[str, str]):222 unmodified lines564 return f"{class_name}({as_list!r}{encoding_str})"565 566 def getlist(self, key: str, split_commas: bool = False) -> typing.List[str]:567 message = "Headers.getlist() is pending deprecation. Use Headers.get_list()"568- warnings.warn(message, PendingDeprecationWarning)568+ warnings.warn(message, DeprecationWarning)569 return self.get_list(key, split_commas=split_commas)570 571 572 USER_AGENT = f"python-httpx/{__version__}"221 unmodified lines794 content, depending on the Content-Encoding used in the response.795 """796 if not hasattr(self, "_decoder"):797 decoders: typing.List[Decoder] = []798- values = self.headers.getlist("content-encoding", split_commas=True)798+ values = self.headers.get_list("content-encoding", split_commas=True)799 for value in values:800 value = value.strip().lower()801 try:802 decoder_cls = SUPPORTED_DECODERS[value]397 unmodified linesmodified:tests/models/test_headers.py+4 added
12 unmodified lines13 assert h["a"] == "123, 456"14 assert h.get("a") == "123, 456"15 assert h.get("nope", default=None) is None16 assert h.get_list("a") == ["123", "456"]17+18+ with pytest.warns(DeprecationWarning):19+ assert h.getlist("a") == ["123", "456"]20+21 assert list(h.keys()) == ["a", "b"]22 assert list(h.values()) == ["123, 456", "789"]23 assert list(h.items()) == [("a", "123, 456"), ("b", "789")]24 assert h.multi_items() == [("a", "123"), ("a", "456"), ("b", "789")]153 unmodified linesmodified:tests/models/test_queryparams.py+4 added
18 unmodified lines19 assert q["a"] == "456"20 assert q.get("a") == "456"21 assert q.get("nope", default=None) is None22 assert q.get_list("a") == ["123", "456"]23+24+ with pytest.warns(DeprecationWarning):25+ assert q.getlist("a") == ["123", "456"]26+27 assert list(q.keys()) == ["a", "b"]28 assert list(q.values()) == ["456", "789"]29 assert list(q.items()) == [("a", "456"), ("b", "789")]30 assert len(q) == 261 unmodified lines