From ccd98b1a6de221fa4b497de7f7bdf89b1347024d Mon Sep 17 00:00:00 2001 From: Will Frey Date: Tue, 30 Aug 2022 07:46:19 -0400 Subject: [PATCH] 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 --- httpx/_models.py | 4 ++-- httpx/_types.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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]], ]