PyDocs

Nav

Development Tools

Never

typing

data
The bottom type, a type that has no members.

This can be used to define a function that should never be
called, or a function that never returns::

    from typing import Never

    def never_call_me(arg: Never) -> None:
        pass

    def int_or_str(arg: int | str) -> None:
        never_call_me(arg)  # type checker error
        match arg:
            case int():
                print("It's an int")
            case str():
                print("It's a str")
            case _:
                never_call_me(arg)  # OK, arg is of type Never
Changed in 3.6.2, 3.11
  • 3.6.2: Added NoReturn.
  • 3.11: Added Never.
0 Examples
No examples for typing/Never.
See Also
No see-alsos for typing/Never
0 Notes
No notes for Never