Skip to content
Closed
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
12 changes: 10 additions & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,12 @@ def check_first_pass(self) -> None:
if self.binder.is_unreachable():
if not self.should_report_unreachable_issues():
break
if not self.is_noop_for_reachability(d):
if self.is_noop_for_reachability(d):
if not isinstance(d, ExpressionStmt) or not isinstance(
d.expr, CallExpr
):
self.accept(d)
else:
self.msg.unreachable_statement(d)
break
else:
Expand Down Expand Up @@ -2948,7 +2953,10 @@ def visit_block(self, b: Block) -> None:
if self.binder.is_unreachable():
if not self.should_report_unreachable_issues():
break
if not self.is_noop_for_reachability(s):
if self.is_noop_for_reachability(s):
if not isinstance(s, ExpressionStmt) or not isinstance(s.expr, CallExpr):
self.accept(s)
else:
self.msg.unreachable_statement(s)
break
else:
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 @@ -1505,6 +1505,14 @@ 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]

[case testLambdaNoReturn]
# flags: --warn-unreachable
from typing import Callable, NoReturn
Expand Down
Loading