Bug Report
There are seemingly trivial cases of unreachable code not being detected at module level, or when the code consists of raise statements.
To Reproduce
from typing import Final from typing import NoReturn def foo() -> NoReturn: raise Exception("foo") def bar() -> NoReturn: foo() # Should trigger [unreachable] but doesn't raise Exception("I shouldn't pass static analysis") def baz() -> NoReturn: raise Exception("baz") # Should trigger [unreachable] but doesn't raise Exception("I shouldn't pass static analysis") def qux() -> None: foo() # Should trigger [unreachable] but doesn't raise Exception("I shouldn't pass static analysis") foo() # Should trigger [unreachable] but doesn't raise Exception("foo") # Should trigger [unreachable] but doesn't(!) MEANING: Final[int] = 42
Expected Behavior
As seen in my example, I would expect the optional [unreachable] check to detect the following examples of unreachable code:
Actual Behavior
The example above type checks with warn_unreachable = True.
Your Environment
[mypy] python_version = 3.8 pretty = True warn_redundant_casts = True warn_unused_ignores = True ignore_missing_imports = True strict_optional = True no_implicit_optional = True show_error_context = True show_column_numbers = True disallow_untyped_calls = True disallow_untyped_defs = True warn_return_any = True warn_unreachable = True show_none_errors = True show_error_codes = True follow_imports = normal namespace_packages = True explicit_package_bases = True
Check module bodies to be reachable (#11361)
Check module bodies to be reachable (python#11361)
Activity
Check module bodies to be reachable (#11361)
Check module bodies to be reachable (python#11361)