]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Relax `HeaderTypes` type alias definition (#2317)
authorWill Frey <jfrey89@gmail.com>
Tue, 30 Aug 2022 11:46:19 +0000 (07:46 -0400)
committerGitHub <noreply@github.com>
Tue, 30 Aug 2022 11:46:19 +0000 (12:46 +0100)
* Relax `HeaderTypes` type alias definition

This replaces `Dict[..., ...]` with `Mapping[..., ...]` in the union definition for `HeaderTypes`. Closes #2314.

* Update _models.py

Co-authored-by: Tom Christie <tom@tomchristie.com>
httpx/_models.py
httpx/_types.py

index 7a3b5885df935a706ff7c727c0dc339db0044279..84739f74d79ca1a97617aaf6525502e3fde53596 100644 (file)
@@ -3,7 +3,7 @@ import email.message
 import json as jsonlib
 import typing
 import urllib.request
-from collections.abc import MutableMapping
+from collections.abc import Mapping, MutableMapping
 from http.cookiejar import Cookie, CookieJar
 
 from ._content import ByteStream, UnattachedStream, encode_request, encode_response
@@ -65,7 +65,7 @@ class Headers(typing.MutableMapping[str, str]):
             self._list = []  # type: typing.List[typing.Tuple[bytes, bytes, bytes]]
         elif isinstance(headers, Headers):
             self._list = list(headers._list)
-        elif isinstance(headers, dict):
+        elif isinstance(headers, Mapping):
             self._list = [
                 (
                     normalize_header_key(k, lower=False, encoding=encoding),
index 784848ef8cc8acc6a2db66563e977dd4ef3c573a..8a50314bd3ef8b6e99b1213e8ea89f6c758628ae 100644 (file)
@@ -43,8 +43,8 @@ QueryParamTypes = Union[
 
 HeaderTypes = Union[
     "Headers",
-    Dict[str, str],
-    Dict[bytes, bytes],
+    Mapping[str, str],
+    Mapping[bytes, bytes],
     Sequence[Tuple[str, str]],
     Sequence[Tuple[bytes, bytes]],
 ]