From a8aa237a91019f2494315cfebe1602ac4a422381 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 11 Jul 2019 10:44:32 +0300 Subject: [PATCH] sys: refine the return type of sys.exc_info() I believe that either all of the items are None or none of them are. Reflect that in the type. This was attempted initially in https://github.com/python/typeshed/pull/246 but apparently mypy didn't allow unpacking given such a union, but it does now (checked with mypy 0.711). The (incorrect) TODO from that PR was removed in commit 25ac4d6af46104d0c7cb134ed09a61ca7092b62a but the commit message noted that this change is desirable. --- stdlib/2/sys.pyi | 2 +- stdlib/3/sys.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2/sys.pyi b/stdlib/2/sys.pyi index e67b26325af1..2b38c6da0c49 100644 --- a/stdlib/2/sys.pyi +++ b/stdlib/2/sys.pyi @@ -8,7 +8,7 @@ from types import FrameType, ModuleType, TracebackType, ClassType # The following type alias are stub-only and do not exist during runtime _ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType] -_OptExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] +_OptExcInfo = Union[_ExcInfo, Tuple[None, None, None]] class _flags: bytes_warning: int diff --git a/stdlib/3/sys.pyi b/stdlib/3/sys.pyi index 3f856bbc9c76..911ff4fe9344 100644 --- a/stdlib/3/sys.pyi +++ b/stdlib/3/sys.pyi @@ -16,7 +16,7 @@ _T = TypeVar('_T') # The following type alias are stub-only and do not exist during runtime _ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType] -_OptExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] +_OptExcInfo = Union[_ExcInfo, Tuple[None, None, None]] # ----- sys variables ----- abiflags: str