Check that statement or expression is unreachable [unreachable]
If you use —warn-unreachable
, mypy generates an error if itthinks that a statement or expression will never be executed. In most cases, this is due toincorrect control flow or conditional checks that are accidentally always true or false.
- # mypy: warn-unreachable
- def example(x: int) -> None:
- # Error: Right operand of 'or' is never evaluated [unreachable]
- assert isinstance(x, int) or x == 'unused'
- return
- # Error: Statement is unreachable [unreachable]
- print('unreachable')