PyDocs

Nav

Development Tools

assert_never

typing

function · Added in 3.11 (source)
  • assert_never(arg, /)
Statically assert that a line of code is unreachable.

Example::

    def int_or_str(arg: int | str) -> None:
        match arg:
            case int():
                print("It's an int")
            case str():
                print("It's a str")
            case _:
                assert_never(arg)

If a type checker finds that a call to assert_never() is
reachable, it will emit an error.

At runtime, this throws an exception when called.
0 Examples
No examples for typing/assert_never.
See Also
No see-alsos for typing/assert_never
0 Notes
No notes for assert_never