File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 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,
37563756 proposed_type = UnionType ([type_range .item for type_range in proposed_type_ranges ])
37573757 if current_type :
37583758 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 )):
37603760 # Expression is always of one of the types in proposed_type_ranges
37613761 return {}, None
37623762 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 ):
37643765 # Expression is never of any type in proposed_type_ranges
37653766 return None , {}
37663767 else :
Original file line number Diff line number Diff line change @@ -1313,6 +1313,23 @@ def f(x: Union[A, B]) -> None:
13131313 f(x)
13141314[builtins fixtures/isinstance.pyi]
13151315
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+
13161333[case testIsinstanceOfSuperclass]
13171334class A: pass
13181335class B(A): pass
You can’t perform that action at this time.
0 commit comments