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.

  1. # mypy: warn-unreachable
  2.  
  3. def example(x: int) -> None:
  4. # Error: Right operand of 'or' is never evaluated [unreachable]
  5. assert isinstance(x, int) or x == 'unused'
  6.  
  7. return
  8. # Error: Statement is unreachable [unreachable]
  9. print('unreachable')