Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
check all statements of the relevant if or else block instead of only…
… the first one (which allows to call `is_noop_for_reachability`).
  • Loading branch information
tyralla committed Oct 20, 2025
commit eb6516b236e48947592e557b51223eb70f751bd4
14 changes: 1 addition & 13 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5054,19 +5054,7 @@ def _visit_if_stmt_redundant_expr_helper(
def _filter(body: Block | None) -> bool:
if body is None:
return False
s = body.body[0]
if isinstance(s, AssertStmt) and is_false_literal(s.expr):
return True
if isinstance(s, RaiseStmt):
return True
elif isinstance(s, ExpressionStmt) and isinstance(s.expr, CallExpr):
with self.expr_checker.msg.filter_errors(filter_revealed_type=True):
typ = self.expr_checker.accept(
s.expr, allow_none_return=True, always_allow_any=True
)
if isinstance(get_proper_type(typ), UninhabitedType):
return True
return False
return all(self.is_noop_for_reachability(s) for s in body.body)

if if_map is None:
if stmt.while_stmt:
Expand Down
17 changes: 17 additions & 0 deletions test-data/unit/check-isinstance.test
Original file line number Diff line number Diff line change
Expand Up @@ -3137,4 +3137,21 @@ def f6(x: Literal[1]) -> None:
if x != 1:
raise ValueError

def f7(x: Literal[1, 2]) -> None:
if x == 1:
y = "a"
elif x == 2:
y = "b"
else:
pass

def f8(x: Literal[1, 2]) -> None:
if x == 1:
y = "a"
elif x == 2: # E: If condition is always true
y = "b"
else:
pass
y = "c"

[builtins fixtures/bool.pyi]
Loading