Skip to content

Commit

Permalink
Check no-op for reachability statements
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Mar 30, 2024
1 parent 4310586 commit 97c5eb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ def check_first_pass(self) -> None:
if not self.is_noop_for_reachability(d):
self.msg.unreachable_statement(d)
break
else:
self.accept(d)
else:
self.accept(d)

Expand Down Expand Up @@ -2791,6 +2793,8 @@ def visit_block(self, b: Block) -> None:
if not self.is_noop_for_reachability(s):
self.msg.unreachable_statement(s)
break
else:
self.accept(s)
else:
self.accept(s)

Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-unreachable-code.test
Original file line number Diff line number Diff line change
Expand Up @@ -1494,3 +1494,11 @@ from typing import Generator
def f() -> Generator[None, None, None]:
return None
yield None

[case testErrorInNoopForReachabilityStatement]
# flags: --warn-unreachable
def double(x: int) -> int:
if not isinstance(x, int):
raise BaseException["Expected an integer"] # E: The type "Type[BaseException]" is not generic and not indexable
return x
[builtins fixtures/tuple.pyi]

0 comments on commit 97c5eb4

Please sign in to comment.