From b532f6be86d2679e5afacd416e74382541370cf3 Mon Sep 17 00:00:00 2001 From: Semyon Moroz Date: Mon, 7 Jul 2025 12:13:54 +0000 Subject: [PATCH] Add attributes to urllib errors (#14332) --- stdlib/urllib/error.pyi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stdlib/urllib/error.pyi b/stdlib/urllib/error.pyi index 89cec9bf2..2173d7e6e 100644 --- a/stdlib/urllib/error.pyi +++ b/stdlib/urllib/error.pyi @@ -6,6 +6,8 @@ __all__ = ["URLError", "HTTPError", "ContentTooShortError"] class URLError(OSError): reason: str | BaseException + # The `filename` attribute only exists if it was provided to `__init__` and wasn't `None`. + filename: str def __init__(self, reason: str | BaseException, filename: str | None = None) -> None: ... class HTTPError(URLError, addinfourl): @@ -16,6 +18,9 @@ class HTTPError(URLError, addinfourl): @property def reason(self) -> str: ... # type: ignore[override] code: int + msg: str + hdrs: Message + fp: IO[bytes] def __init__(self, url: str, code: int, msg: str, hdrs: Message, fp: IO[bytes] | None) -> None: ... class ContentTooShortError(URLError):