From: Will Frey Date: Tue, 30 Aug 2022 11:46:19 +0000 (-0400) Subject: Relax `HeaderTypes` type alias definition (#2317) X-Git-Tag: 0.23.1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ccd98b1a6de221fa4b497de7f7bdf89b1347024d;p=thirdparty%2Fhttpx.git Relax `HeaderTypes` type alias definition (#2317) * 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 --- diff --git a/httpx/_models.py b/httpx/_models.py index 7a3b5885..84739f74 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -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), diff --git a/httpx/_types.py b/httpx/_types.py index 784848ef..8a50314b 100644 --- a/httpx/_types.py +++ b/httpx/_types.py @@ -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]], ]