From 9b3cb1a9d060c6128d6ad1bcd4b049b9b2cbc443 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Fri, 11 Oct 2019 13:27:59 +0200 Subject: [PATCH 1/2] Change type for urllib headers from Mapping to email.message.Message (#3344) While the Message class implements a mapping, it also has many additional methods available. --- stdlib/3/urllib/response.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/3/urllib/response.pyi b/stdlib/3/urllib/response.pyi index 7cbc045a3f76..dca0efacc474 100644 --- a/stdlib/3/urllib/response.pyi +++ b/stdlib/3/urllib/response.pyi @@ -1,6 +1,7 @@ # private module, we only expose what's needed from typing import BinaryIO, Iterable, List, Mapping, Optional, Type, TypeVar +from email.message import Message from types import TracebackType _AIUT = TypeVar("_AIUT", bound=addbase) @@ -31,8 +32,8 @@ class addbase(BinaryIO): def writelines(self, lines: Iterable[bytes]) -> None: ... class addinfo(addbase): - headers: Mapping[str, str] - def info(self) -> Mapping[str, str]: ... + headers: Message + def info(self) -> Message: ... class addinfourl(addinfo): url: str From 789f84408f08bbe6079965a4ba14bd20328bf647 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Fri, 11 Oct 2019 14:26:12 +0200 Subject: [PATCH 2/2] Remove override of 'headers' in HTTPError Previously, the override changed a Mapping (immutable) into a Dict (mutable). Since the 'email.message.Message' class is already mutable, there is no need to override anymore. --- stdlib/3/urllib/error.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/3/urllib/error.pyi b/stdlib/3/urllib/error.pyi index 191c765edb88..16ceae8fc838 100644 --- a/stdlib/3/urllib/error.pyi +++ b/stdlib/3/urllib/error.pyi @@ -7,6 +7,5 @@ class URLError(IOError): reason: Union[str, BaseException] class HTTPError(URLError, addinfourl): code: int - headers: Dict[str, str] def __init__(self, url, code, msg, hdrs, fp) -> None: ... class ContentTooShortError(URLError): ...