@@ -110,3 +110,48 @@ def g(x: int): ...
110
110
[case testWalrus]
111
111
if (a := 2):
112
112
reveal_type(a) # E: Revealed type is 'builtins.int'
113
+
114
+ while (b := "x"):
115
+ reveal_type(b) # E: Revealed type is 'builtins.str'
116
+
117
+ def f(x: int = (c := 4)) -> None:
118
+ if (a := 2):
119
+ reveal_type(a) # E: Revealed type is 'builtins.int'
120
+
121
+ while (b := "x"):
122
+ reveal_type(b) # E: Revealed type is 'builtins.str'
123
+
124
+ x = (y := 1) + (z := 2)
125
+ reveal_type(x) # E: Revealed type is 'builtins.int'
126
+ reveal_type(y) # E: Revealed type is 'builtins.int'
127
+ reveal_type(z) # E: Revealed type is 'builtins.int'
128
+
129
+ l = [y2 := 1, y2 + 2, y2 + 3]
130
+ reveal_type(y2) # E: Revealed type is 'builtins.int'
131
+ reveal_type(l) # E: Revealed type is 'builtins.list[builtins.int*]'
132
+
133
+ filtered_data = [y3 for x in l if (y3 := a) is not None]
134
+ reveal_type(filtered_data) # E: Revealed type is 'builtins.list[builtins.int*]'
135
+ # TODO this should be valid: https://www.python.org/dev/peps/pep-0572/#scope-of-the-target
136
+ y3 # E: Name 'y3' is not defined
137
+
138
+ # https://www.python.org/dev/peps/pep-0572/#exceptional-cases
139
+ (y4 := 3)
140
+ reveal_type(y4) # E: Revealed type is 'builtins.int'
141
+
142
+ y5 = (y6 := 3)
143
+ reveal_type(y5) # E: Revealed type is 'builtins.int'
144
+ reveal_type(y6) # E: Revealed type is 'builtins.int'
145
+
146
+ f(x=(y7 := 3))
147
+ reveal_type(y7) # E: Revealed type is 'builtins.int'
148
+
149
+ reveal_type((lambda: (y8 := 3) and y8)()) # E: Revealed type is 'builtins.int'
150
+
151
+ y7 = 1.0 # E: Incompatible types in assignment (expression has type "float", variable has type "int")
152
+ if y7 := "x": # E: Incompatible types in assignment (expression has type "str", variable has type "int")
153
+ pass
154
+
155
+ reveal_type(c) # E: Revealed type is 'builtins.int'
156
+
157
+ [builtins fixtures/f_string.pyi]
0 commit comments