Skip to content

Commit 401a4e0

Browse files
authored
Re-enable promotions in isinstance checks (#6181)
This pull request reverts #6114 and #6142: see #6180 for rationale. In short, the original fix ended up being more disruptive then anticipated: it's modifying str and unicode semantics, and we should put a little more thought into reasoning about that particular case before moving ahead with any fix here. This should also help unblock the upcoming 0.660 release.
1 parent e6f111a commit 401a4e0

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

mypy/checker.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3766,21 +3766,19 @@ def conditional_type_map(expr: Expression,
37663766
proposed_type = UnionType([type_range.item for type_range in proposed_type_ranges])
37673767
if current_type:
37683768
if (not any(type_range.is_upper_bound for type_range in proposed_type_ranges)
3769-
and is_proper_subtype(current_type, proposed_type, ignore_promotions=True)):
3769+
and is_proper_subtype(current_type, proposed_type)):
37703770
# Expression is always of one of the types in proposed_type_ranges
37713771
return {}, None
37723772
elif not is_overlapping_types(current_type, proposed_type,
3773-
prohibit_none_typevar_overlap=True,
3774-
ignore_promotions=True):
3773+
prohibit_none_typevar_overlap=True):
37753774
# Expression is never of any type in proposed_type_ranges
37763775
return None, {}
37773776
else:
37783777
# we can only restrict when the type is precise, not bounded
37793778
proposed_precise_type = UnionType([type_range.item
37803779
for type_range in proposed_type_ranges
37813780
if not type_range.is_upper_bound])
3782-
remaining_type = restrict_subtype_away(current_type, proposed_precise_type,
3783-
ignore_promotions=True)
3781+
remaining_type = restrict_subtype_away(current_type, proposed_precise_type)
37843782
return {expr: proposed_type}, {expr: remaining_type}
37853783
else:
37863784
return {expr: proposed_type}, {}

test-data/unit/check-isinstance.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,8 @@ def f(x: Union[A, B]) -> None:
13131313
f(x)
13141314
[builtins fixtures/isinstance.pyi]
13151315

1316-
[case testIsinstanceWithOverlappingPromotionTypes]
1316+
[case testIsinstanceWithOverlappingPromotionTypes-skip]
1317+
# Currently disabled: see https://github.com/python/mypy/issues/6180 for context
13171318
from typing import Union
13181319

13191320
class FloatLike: pass

0 commit comments

Comments
 (0)