From c9d33d8cc47ac5a7cf25c8d6c617d654708c3906 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 19 Sep 2023 19:32:08 -0700 Subject: [PATCH 1/2] typing.pyi: IO.name may be bytes Fixes #10737 Worried this may be too disruptive, but let's see what mypy-primer says. --- stdlib/typing.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 2c1ebe6d7f95..d43c5031280f 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -710,7 +710,7 @@ class IO(Iterator[AnyStr], Generic[AnyStr]): @property def mode(self) -> str: ... @property - def name(self) -> str: ... + def name(self) -> str | bytes: ... @abstractmethod def close(self) -> None: ... @property From 050b7a93a0dea73ab175c0bceb05987287f57c44 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 19 Sep 2023 20:04:20 -0700 Subject: [PATCH 2/2] Update typing.pyi --- stdlib/typing.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index d43c5031280f..6deb0ffd02b3 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -709,8 +709,10 @@ class IO(Iterator[AnyStr], Generic[AnyStr]): # See #8726 @property def mode(self) -> str: ... + # Usually str, but may be bytes if a bytes path was passed to open(). See #10737. + # If PEP 696 becomes available, we may want to use a defaulted TypeVar here. @property - def name(self) -> str | bytes: ... + def name(self) -> str | Any: ... @abstractmethod def close(self) -> None: ... @property