File tree 1 file changed +22
-0
lines changed 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -338,6 +338,28 @@ def check_narrow(x: Optional[int], s: List[int]) -> None:
338
338
if isinstance((y := x), int):
339
339
reveal_type(y) # N: Revealed type is 'builtins.int'
340
340
341
+ class AssignmentExpressionsClass:
342
+ x = (y := 1) + (z := 2)
343
+ reveal_type(z) # N: Revealed type is 'builtins.int'
344
+
345
+ l = [x2 := 1, 2, 3]
346
+ reveal_type(x2) # N: Revealed type is 'builtins.int'
347
+
348
+ def __init__(self) -> None:
349
+ reveal_type(self.z) # N: Revealed type is 'builtins.int'
350
+
351
+ l = [z2 := 1, z2 + 2, z2 + 3]
352
+ reveal_type(z2) # N: Revealed type is 'builtins.int'
353
+ reveal_type(l) # N: Revealed type is 'builtins.list[builtins.int*]'
354
+
355
+ filtered_data = [z3 for x in l if (z3 := 1) is not None]
356
+ reveal_type(filtered_data) # N: Revealed type is 'builtins.list[builtins.int*]'
357
+ reveal_type(z3) # N: Revealed type is 'builtins.int'
358
+
359
+ # Assignment expressions from inside the class should not escape the class scope.
360
+ reveal_type(x2) # E: Name 'x2' is not defined # N: Revealed type is 'Any'
361
+ reveal_type(z2) # E: Name 'z2' is not defined # N: Revealed type is 'Any'
362
+
341
363
[builtins fixtures/isinstancelist.pyi]
342
364
343
365
[case testWalrusPartialTypes]
You can’t perform that action at this time.
0 commit comments