]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Use get_list consistently (#1119)
authorTom Christie <tom@tomchristie.com>
Sun, 2 Aug 2020 10:33:50 +0000 (11:33 +0100)
committerGitHub <noreply@github.com>
Sun, 2 Aug 2020 10:33:50 +0000 (11:33 +0100)
* Use get_list consistently

* Ensure DeprecationWarning on getlist vs. get_list

httpx/_models.py
tests/models/test_headers.py
tests/models/test_queryparams.py

index 30032a1984ab166fb3b65163957df0fd08945903..9c5aa1773a241f9e62579e25514728bfd0c2176e 100644 (file)
@@ -281,7 +281,7 @@ class QueryParams(typing.Mapping[str, str]):
 
         params = QueryParams(params)
         for param in params:
-            item, *extras = params.getlist(param)
+            item, *extras = params.get_list(param)
             self[param] = item
             if extras:
                 self._list.extend((param, e) for e in extras)
@@ -334,7 +334,7 @@ class QueryParams(typing.Mapping[str, str]):
         message = (
             "QueryParams.getlist() is pending deprecation. Use QueryParams.get_list()"
         )
-        warnings.warn(message, PendingDeprecationWarning)
+        warnings.warn(message, DeprecationWarning)
         return self.get_list(key)
 
 
@@ -565,7 +565,7 @@ class Headers(typing.MutableMapping[str, str]):
 
     def getlist(self, key: str, split_commas: bool = False) -> typing.List[str]:
         message = "Headers.getlist() is pending deprecation. Use Headers.get_list()"
-        warnings.warn(message, PendingDeprecationWarning)
+        warnings.warn(message, DeprecationWarning)
         return self.get_list(key, split_commas=split_commas)
 
 
@@ -795,7 +795,7 @@ class Response:
         """
         if not hasattr(self, "_decoder"):
             decoders: typing.List[Decoder] = []
-            values = self.headers.getlist("content-encoding", split_commas=True)
+            values = self.headers.get_list("content-encoding", split_commas=True)
             for value in values:
                 value = value.strip().lower()
                 try:
index 7d090f2b32d0075d05c7fe3fc97bf21e1afa2aed..8c1042105d0228e1e5668da3ee8c99d75d014f59 100644 (file)
@@ -14,6 +14,10 @@ def test_headers():
     assert h.get("a") == "123, 456"
     assert h.get("nope", default=None) is None
     assert h.get_list("a") == ["123", "456"]
+
+    with pytest.warns(DeprecationWarning):
+        assert h.getlist("a") == ["123", "456"]
+
     assert list(h.keys()) == ["a", "b"]
     assert list(h.values()) == ["123, 456", "789"]
     assert list(h.items()) == [("a", "123, 456"), ("b", "789")]
index 39f57e2e7f8c00a70f49e933c1a5f048100d72b9..d0d3b3faa4568a2a09fdc50283aa08f0d29cc6cc 100644 (file)
@@ -20,6 +20,10 @@ def test_queryparams(source):
     assert q.get("a") == "456"
     assert q.get("nope", default=None) is None
     assert q.get_list("a") == ["123", "456"]
+
+    with pytest.warns(DeprecationWarning):
+        assert q.getlist("a") == ["123", "456"]
+
     assert list(q.keys()) == ["a", "b"]
     assert list(q.values()) == ["456", "789"]
     assert list(q.items()) == [("a", "456"), ("b", "789")]