Skip to content

Commit 2bd0802

Browse files
committed
Narrow walrus to Never if unreachable
1 parent 22e73d5 commit 2bd0802

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

mypy/checker.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6228,12 +6228,17 @@ def find_isinstance_check_helper(
62286228

62296229
if if_condition_map is not None:
62306230
if_map.update(if_condition_map)
6231+
else:
6232+
if_map[node.target] = UninhabitedType()
6233+
62316234
if else_condition_map is not None:
62326235
else_map.update(else_condition_map)
6236+
else:
6237+
else_map[node.target] = UninhabitedType()
62336238

62346239
return (
6235-
(None if if_assignment_map is None or if_condition_map is None else if_map),
6236-
(None if else_assignment_map is None or else_condition_map is None else else_map),
6240+
(None if if_assignment_map is None else if_map),
6241+
(None if else_assignment_map is None else else_map),
62376242
)
62386243
elif isinstance(node, OpExpr) and node.op == "and":
62396244
left_if_vars, left_else_vars = self.find_isinstance_check(node.left)

test-data/unit/check-python38.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def check_partial_list() -> None:
460460

461461
if (x := 0):
462462
reveal_type(x) # E: Statement is unreachable \
463-
# N: Revealed type is "builtins.int"
463+
# N: Revealed type is "Never"
464464
else:
465465
reveal_type(x) # N: Revealed type is "Literal[0]"
466466

0 commit comments

Comments
 (0)