Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tyralla committed Nov 23, 2024
1 parent 82106db commit 9b0ec61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-narrowing.test
Original file line number Diff line number Diff line change
Expand Up @@ -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[<type>] = ...")
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]

0 comments on commit 9b0ec61

Please sign in to comment.