Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check no-op for reachability statements #17080

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Loading