Skip to content

Commit 0b94a3e

Browse files
committed
threading: fix ExceptHookArgs being a function instead of a type
The previous typing meant `threading.ExceptHookArgs` could not be used to type a value. The new typing follows what cpython does in the happy path (`_thread` exists rather than the pure-python fallback being used). Fixes python#4767.
1 parent 8c20938 commit 0b94a3e

File tree

5 files changed

+13
-26
lines changed

5 files changed

+13
-26
lines changed

stdlib/2and3/_dummy_threading.pyi

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,7 @@ class Event:
155155
def wait(self, timeout: Optional[float] = ...) -> bool: ...
156156

157157
if sys.version_info >= (3, 8):
158-
import _thread
159-
160-
# don't ask...
161-
_ExceptHookArgs = _thread.ExceptHookArgs
162-
ExceptHookArgs = _thread._ExceptHookArgs
163-
164-
excepthook: Callable[[_ExceptHookArgs], Any]
158+
from _thread import _excepthook as excepthook, _ExceptHookArgs as ExceptHookArgs
165159

166160
class Timer(Thread):
167161
if sys.version_info >= (3,):

stdlib/2and3/threading.pyi

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,7 @@ class Event:
155155
def wait(self, timeout: Optional[float] = ...) -> bool: ...
156156

157157
if sys.version_info >= (3, 8):
158-
import _thread
159-
160-
# don't ask...
161-
_ExceptHookArgs = _thread.ExceptHookArgs
162-
ExceptHookArgs = _thread._ExceptHookArgs
163-
164-
excepthook: Callable[[_ExceptHookArgs], Any]
158+
from _thread import _excepthook as excepthook, _ExceptHookArgs as ExceptHookArgs
165159

166160
class Timer(Thread):
167161
if sys.version_info >= (3,):

stdlib/3/_thread.pyi

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from threading import Thread
33
from types import TracebackType
4-
from typing import Any, Callable, Dict, NamedTuple, NoReturn, Optional, Tuple, Type
4+
from typing import Any, Callable, Dict, NoReturn, Optional, Tuple, Type
55

66
error = RuntimeError
77

@@ -29,10 +29,13 @@ TIMEOUT_MAX: float
2929

3030
if sys.version_info >= (3, 8):
3131
def get_native_id() -> int: ... # only available on some platforms
32-
class ExceptHookArgs(NamedTuple):
33-
exc_type: Type[BaseException]
34-
exc_value: Optional[BaseException]
35-
exc_traceback: Optional[TracebackType]
36-
thread: Optional[Thread]
37-
def _ExceptHookArgs(args: Any) -> ExceptHookArgs: ...
38-
_excepthook: Callable[[ExceptHookArgs], Any]
32+
class _ExceptHookArgs(Tuple[Type[BaseException], Optional[BaseException], Optional[TracebackType], Optional[Thread]]):
33+
@property
34+
def exc_type(self) -> Type[BaseException]: ...
35+
@property
36+
def exc_value(self) -> Optional[BaseException]: ...
37+
@property
38+
def exc_traceback(self) -> Optional[TracebackType]: ...
39+
@property
40+
def thread(self) -> Optional[Thread]: ...
41+
_excepthook: Callable[[_ExceptHookArgs], Any]

tests/stubtest_whitelists/py38.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
_thread.ExceptHookArgs
2-
_thread._ExceptHookArgs
31
ast.Bytes.__new__
42
ast.Ellipsis.__new__
53
ast.NameConstant.__new__

tests/stubtest_whitelists/py39.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
_ast.ImportFrom.level
22
_dummy_thread
3-
_thread.ExceptHookArgs
4-
_thread._ExceptHookArgs
53
ast.Bytes.__new__
64
ast.Ellipsis.__new__
75
ast.ExtSlice.__new__

0 commit comments

Comments
 (0)