Skip to content

Commit 53553e7

Browse files
committed
Don't check unreachable code with partial types
1 parent 13ad1cb commit 53553e7

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

mypy/checker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,12 @@ def accept_loop(
599599
partials_old = sum(len(pts.map) for pts in self.partial_types)
600600

601601
# Disable error types that we cannot safely identify in intermediate iteration steps:
602-
warn_unreachable = self.options.warn_unreachable
603602
warn_redundant = codes.REDUNDANT_EXPR in self.options.enabled_error_codes
604-
self.options.warn_unreachable = False
605603
self.options.enabled_error_codes.discard(codes.REDUNDANT_EXPR)
606604

607605
while True:
608606
with self.binder.frame_context(can_skip=True, break_frame=2, continue_frame=1):
607+
self.binder.suppress_unreachable_warnings()
609608
if on_enter_body is not None:
610609
on_enter_body()
611610

@@ -616,10 +615,9 @@ def accept_loop(
616615
partials_old = partials_new
617616

618617
# If necessary, reset the modified options and make up for the postponed error checks:
619-
self.options.warn_unreachable = warn_unreachable
620618
if warn_redundant:
621619
self.options.enabled_error_codes.add(codes.REDUNDANT_EXPR)
622-
if warn_unreachable or warn_redundant:
620+
if self.options.warn_unreachable or warn_redundant:
623621
with self.binder.frame_context(can_skip=True, break_frame=2, continue_frame=1):
624622
if on_enter_body is not None:
625623
on_enter_body()

test-data/unit/check-narrowing.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,8 +2369,7 @@ def fn_while(arg: T) -> None:
23692369
x = None
23702370
for _ in range(2):
23712371
if x is not None:
2372-
reveal_type(x) # N: Revealed type is "Never" \
2373-
# N: Revealed type is "builtins.int"
2372+
reveal_type(x) # N: Revealed type is "builtins.int"
23742373
x = 1
23752374
reveal_type(x) # N: Revealed type is "Union[builtins.int, None]"
23762375

0 commit comments

Comments
 (0)