ID EN
Typing

assert_never

Python 3.11

Ask a static type checker to confirm that a line of code is unreachable.

Syntax

PYTHON
typing.assert_never(arg, /)

Examples

Example 1
PYTHON
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 _ as unreachable:
            assert_never(unreachable)

See Also

int str float Never