File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -3756,11 +3756,12 @@ def conditional_type_map(expr: Expression,
3756
3756
proposed_type = UnionType ([type_range .item for type_range in proposed_type_ranges ])
3757
3757
if current_type :
3758
3758
if (not any (type_range .is_upper_bound for type_range in proposed_type_ranges )
3759
- and is_proper_subtype (current_type , proposed_type )):
3759
+ and is_proper_subtype (current_type , proposed_type , ignore_promotions = True )):
3760
3760
# Expression is always of one of the types in proposed_type_ranges
3761
3761
return {}, None
3762
3762
elif not is_overlapping_types (current_type , proposed_type ,
3763
- prohibit_none_typevar_overlap = True ):
3763
+ prohibit_none_typevar_overlap = True ,
3764
+ ignore_promotions = True ):
3764
3765
# Expression is never of any type in proposed_type_ranges
3765
3766
return None , {}
3766
3767
else :
Original file line number Diff line number Diff line change @@ -1313,6 +1313,23 @@ def f(x: Union[A, B]) -> None:
1313
1313
f(x)
1314
1314
[builtins fixtures/isinstance.pyi]
1315
1315
1316
+ [case testIsinstanceWithOverlappingPromotionTypes]
1317
+ from typing import Union
1318
+
1319
+ class FloatLike: pass
1320
+ class IntLike(FloatLike): pass
1321
+
1322
+ def f1(x: Union[float, int]) -> None:
1323
+ # We ignore promotions in isinstance checks
1324
+ if isinstance(x, float):
1325
+ reveal_type(x) # E: Revealed type is 'builtins.float'
1326
+
1327
+ def f2(x: Union[FloatLike, IntLike]) -> None:
1328
+ # ...but not regular subtyping relationships
1329
+ if isinstance(x, FloatLike):
1330
+ reveal_type(x) # E: Revealed type is 'Union[__main__.FloatLike, __main__.IntLike]'
1331
+ [builtins fixtures/isinstance.pyi]
1332
+
1316
1333
[case testIsinstanceOfSuperclass]
1317
1334
class A: pass
1318
1335
class B(A): pass
You can’t perform that action at this time.
0 commit comments