From 5c38ce9d2c1c2780076681b45a4ff227eef0cca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Mon, 17 Nov 2025 10:06:50 -0600 Subject: [PATCH] [stdlib] Add a comment to the alias for the return type of `urllib.request.urlopen` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It explains the actual expected types and why `Any` is used. Signed-off-by: Edgar Ramírez-Mondragón --- stdlib/urllib/request.pyi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stdlib/urllib/request.pyi b/stdlib/urllib/request.pyi index 876b9d3f165c..a00e7406ee1e 100644 --- a/stdlib/urllib/request.pyi +++ b/stdlib/urllib/request.pyi @@ -49,7 +49,14 @@ if sys.version_info < (3, 14): __all__ += ["URLopener", "FancyURLopener"] _T = TypeVar("_T") + +# The actual type is `addinfourl | HTTPResponse`, but users would need to use `typing.cast` or `isinstance` to narrow the type, +# so we use `Any` instead. +# See +# - https://github.com/python/typeshed/pull/15042 +# - https://github.com/python/typing/issues/566 _UrlopenRet: TypeAlias = Any + _DataType: TypeAlias = ReadableBuffer | SupportsRead[bytes] | Iterable[bytes] | None if sys.version_info >= (3, 13):