diff --git a/mypy/checker.py b/mypy/checker.py index e72bbb8aee0d..b966492315c7 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -607,11 +607,11 @@ def accept_loop( """ # The outer frame accumulates the results of all iterations with self.binder.frame_context(can_skip=False, conditional_frame=True): - partials_old = len(self.partial_types[0].map) + partials_old = sum(len(pts.map) for pts in self.partial_types) while True: with self.binder.frame_context(can_skip=True, break_frame=2, continue_frame=1): self.accept(body) - partials_new = len(self.partial_types[0].map) + partials_new = sum(len(pts.map) for pts in self.partial_types) if (partials_new == partials_old) and not self.binder.last_pop_changed: break partials_old = partials_new diff --git a/test-data/unit/check-narrowing.test b/test-data/unit/check-narrowing.test index 1bf1eca6e833..ad59af01010c 100644 --- a/test-data/unit/check-narrowing.test +++ b/test-data/unit/check-narrowing.test @@ -2379,4 +2379,13 @@ def g() -> None: z[0] + "v" # E: Unsupported operand types for + ("int" and "str") z.append(1) +class A: + def g(self) -> None: + z = [] # E: Need type annotation for "z" (hint: "z: List[] = ...") + for i in range(2): + while f(): + if z: + z[0] + "v" # E: Unsupported operand types for + ("int" and "str") + z.append(1) + [builtins fixtures/primitives.pyi]