File tree Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change @@ -310,8 +310,6 @@ i = None # type: str
310
310
j = not b and i
311
311
if j:
312
312
reveal_type(j) # E: Revealed type is 'builtins.str'
313
-
314
-
315
313
[builtins fixtures/bool.pyi]
316
314
317
315
[case testRestrictedTypeOr]
@@ -321,7 +319,13 @@ i = None # type: str
321
319
j = b or i
322
320
if not j:
323
321
reveal_type(j) # E: Revealed type is 'builtins.str'
322
+ [builtins fixtures/bool.pyi]
323
+
324
+ [case testAndOr]
324
325
326
+ s = ""
327
+ b = bool()
328
+ reveal_type(s and b or b) # E: Revealed type is 'builtins.bool'
325
329
[builtins fixtures/bool.pyi]
326
330
327
331
[case testNonBooleanOr]
Original file line number Diff line number Diff line change @@ -1165,3 +1165,24 @@ reveal_type(l) # E: Revealed type is 'builtins.list[builtins.int*]'
1165
1165
reveal_type(g) # E: Revealed type is 'typing.Iterator[builtins.int*]'
1166
1166
reveal_type(d) # E: Revealed type is 'builtins.dict[builtins.int*, builtins.int*]'
1167
1167
[builtins fixtures/isinstancelist.pyi]
1168
+
1169
+ [case testIsinstanceInWrongOrderInBooleanOp]
1170
+ class A:
1171
+ m = 1
1172
+ def f(x: object) -> None:
1173
+ if x.m and isinstance(x, A) or False: # E: "object" has no attribute "m"
1174
+ pass
1175
+ [builtins fixtures/isinstance.pyi]
1176
+ [out]
1177
+ main: note: In function "f":
1178
+
1179
+ [case testIsinstanceAndOr]
1180
+ class A:
1181
+ a = None # type: A
1182
+
1183
+ def f(x: object) -> None:
1184
+ b = isinstance(x, A) and x.a or A()
1185
+ reveal_type(b) # E: Revealed type is '__main__.A'
1186
+ [builtins fixtures/isinstance.pyi]
1187
+ [out]
1188
+ main: note: In function "f":
Original file line number Diff line number Diff line change 77
77
reveal_type(x) # E: Revealed type is 'builtins.int'
78
78
[builtins fixtures/bool.pyi]
79
79
80
+ [case testOrCases]
81
+ from typing import Optional
82
+ x = None # type: Optional[str]
83
+ y1 = x or 'a'
84
+ reveal_type(y1) # E: Revealed type is 'builtins.str'
85
+ y2 = x or 1
86
+ reveal_type(y2) # E: Revealed type is 'Union[builtins.str, builtins.int]'
87
+ z1 = 'a' or x
88
+ reveal_type(z1) # E: Revealed type is 'Union[builtins.str, builtins.None]'
89
+ z2 = 1 or x
90
+ reveal_type(z2) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.None]'
91
+
92
+ [case testAndCases]
93
+ from typing import Optional
94
+ x = None # type: Optional[str]
95
+ y1 = x and 'b'
96
+ reveal_type(y1) # E: Revealed type is 'Union[builtins.str, builtins.None]'
97
+ y2 = x and 1 # x could be '', so...
98
+ reveal_type(y2) # E: Revealed type is 'Union[builtins.str, builtins.None, builtins.int]'
99
+ z1 = 'b' and x
100
+ reveal_type(z1) # E: Revealed type is 'Union[builtins.str, builtins.None]'
101
+ z2 = 1 and x
102
+ reveal_type(z2) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.None]'
103
+
80
104
[case testLambdaReturningNone]
81
105
f = lambda: None
82
106
x = f()
You can’t perform that action at this time.
0 commit comments