From: Tom Christie Date: Sun, 2 Aug 2020 10:33:50 +0000 (+0100) Subject: Use get_list consistently (#1119) X-Git-Tag: 0.14.0~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5f87434a54ef8bffec0b9c351d1d4c15bee7aab;p=thirdparty%2Fhttpx.git Use get_list consistently (#1119) * Use get_list consistently * Ensure DeprecationWarning on getlist vs. get_list --- diff --git a/httpx/_models.py b/httpx/_models.py index 30032a19..9c5aa177 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -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: diff --git a/tests/models/test_headers.py b/tests/models/test_headers.py index 7d090f2b..8c104210 100644 --- a/tests/models/test_headers.py +++ b/tests/models/test_headers.py @@ -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")] diff --git a/tests/models/test_queryparams.py b/tests/models/test_queryparams.py index 39f57e2e..d0d3b3fa 100644 --- a/tests/models/test_queryparams.py +++ b/tests/models/test_queryparams.py @@ -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")]