File tree Expand file tree Collapse file tree 4 files changed +44
-3
lines changed Expand file tree Collapse file tree 4 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -607,11 +607,14 @@ def accept_loop(
607
607
"""
608
608
# The outer frame accumulates the results of all iterations
609
609
with self .binder .frame_context (can_skip = False , conditional_frame = True ):
610
+ partials_old = sum (len (pts .map ) for pts in self .partial_types )
610
611
while True :
611
612
with self .binder .frame_context (can_skip = True , break_frame = 2 , continue_frame = 1 ):
612
613
self .accept (body )
613
- if not self .binder .last_pop_changed :
614
+ partials_new = sum (len (pts .map ) for pts in self .partial_types )
615
+ if (partials_new == partials_old ) and not self .binder .last_pop_changed :
614
616
break
617
+ partials_old = partials_new
615
618
if exit_condition :
616
619
_ , else_map = self .find_isinstance_check (exit_condition )
617
620
self .push_type_map (else_map )
Original file line number Diff line number Diff line change @@ -200,9 +200,9 @@ wtvr = next(i for i in range(10) if i == 5)
200
200
201
201
d1 = {1: 2}
202
202
203
- # Make sure we can produce an error when we hit the awful None case
203
+ # Since PR 18180, the following pattern should pose no problems anymore:
204
204
def f(l: List[object]) -> None:
205
- x = None # E: Local variable "x" has inferred type None; add an annotation
205
+ x = None
206
206
for i in l:
207
207
if x is None:
208
208
x = i
Original file line number Diff line number Diff line change @@ -2352,3 +2352,40 @@ def fn_while(arg: T) -> None:
2352
2352
return None
2353
2353
return None
2354
2354
[builtins fixtures/primitives.pyi]
2355
+
2356
+ [case testRefinePartialTypeWithinLoop]
2357
+
2358
+ x = None
2359
+ for _ in range(2):
2360
+ if x is not None:
2361
+ reveal_type(x) # N: Revealed type is "builtins.int"
2362
+ x = 1
2363
+ reveal_type(x) # N: Revealed type is "Union[builtins.int, None]"
2364
+
2365
+ def f() -> bool: ...
2366
+
2367
+ y = None
2368
+ while f():
2369
+ reveal_type(y) # N: Revealed type is "None" \
2370
+ # N: Revealed type is "Union[builtins.int, None]"
2371
+ y = 1
2372
+ reveal_type(y) # N: Revealed type is "Union[builtins.int, None]"
2373
+
2374
+ z = [] # E: Need type annotation for "z" (hint: "z: List[<type>] = ...")
2375
+ def g() -> None:
2376
+ for i in range(2):
2377
+ while f():
2378
+ if z:
2379
+ z[0] + "v" # E: Unsupported operand types for + ("int" and "str")
2380
+ z.append(1)
2381
+
2382
+ class A:
2383
+ def g(self) -> None:
2384
+ z = [] # E: Need type annotation for "z" (hint: "z: List[<type>] = ...")
2385
+ for i in range(2):
2386
+ while f():
2387
+ if z:
2388
+ z[0] + "v" # E: Unsupported operand types for + ("int" and "str")
2389
+ z.append(1)
2390
+
2391
+ [builtins fixtures/primitives.pyi]
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ class memoryview(Sequence[int]):
48
48
class tuple (Generic [T ]):
49
49
def __contains__ (self , other : object ) -> bool : pass
50
50
class list (Sequence [T ]):
51
+ def append (self , v : T ) -> None : pass
51
52
def __iter__ (self ) -> Iterator [T ]: pass
52
53
def __contains__ (self , other : object ) -> bool : pass
53
54
def __getitem__ (self , item : int ) -> T : pass
You can’t perform that action at this time.
0 commit comments