Thanks to visit codestin.com
Credit goes to github.com

Skip to content

threading: ExceptHookArgs funkiness #4767

Description

@bluetech

The threading.excepthook variable (added in Python 3.8) accepts a threading.ExceptHookArgs argument (available at runtime). The typing around it in typeshed is not straightforward:

if sys.version_info >= (3, 8):
import _thread
# don't ask...
_ExceptHookArgs = _thread.ExceptHookArgs
ExceptHookArgs = _thread._ExceptHookArgs
excepthook: Callable[[_ExceptHookArgs], Any]

Sorry but I guess I have to ask 😀

The _thread part is:

if sys.version_info >= (3, 8):
def get_native_id() -> int: ... # only available on some platforms
class ExceptHookArgs(NamedTuple):
exc_type: Type[BaseException]
exc_value: Optional[BaseException]
exc_traceback: Optional[TracebackType]
thread: Optional[Thread]
def _ExceptHookArgs(args: Any) -> ExceptHookArgs: ...
_excepthook: Callable[[ExceptHookArgs], Any]

My practical issue is that this:

import threading

def my_hook(args: threading.ExceptHookArgs) -> None:
    ...

results in

Function "_thread._ExceptHookArgs" is not valid as a type  [valid-type]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions