Skip to content

Commit 6bd339b

Browse files
committed
Rename expansion-related locals/functions
No longer only works on enums
1 parent 621ee50 commit 6bd339b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

mypy/checker.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
map_type_from_supertype, bind_self, erase_to_bound, make_simplified_union,
5050
erase_def_to_union_or_bound, erase_to_union_or_bound, coerce_to_literal,
5151
try_getting_str_literals_from_type, try_getting_int_literals_from_type,
52-
tuple_fallback, is_singleton_type, try_expanding_enum_to_union,
52+
tuple_fallback, is_singleton_type, try_expanding_sum_type_to_union,
5353
true_only, false_only, function_type, get_type_vars, custom_special_method,
5454
is_literal_type_like,
5555
)
@@ -4481,6 +4481,7 @@ def refine_identity_comparison_expression(self,
44814481

44824482
target = None # type: Optional[Type]
44834483
possible_target_indices = []
4484+
44844485
for i in chain_indices:
44854486
expr_type = operand_types[i]
44864487
if should_coerce:
@@ -4534,11 +4535,11 @@ def refine_identity_comparison_expression(self,
45344535
if singleton_index == -1:
45354536
singleton_index = possible_target_indices[-1]
45364537

4537-
enum_name = None
4538+
sum_type_name = None
45384539
target = get_proper_type(target)
45394540
if (isinstance(target, LiteralType) and
45404541
(target.is_enum_literal() or target.fallback.type.fullname == "builtins.bool")):
4541-
enum_name = target.fallback.type.fullname
4542+
sum_type_name = target.fallback.type.fullname
45424543

45434544
target_type = [TypeRange(target, is_upper_bound=False)]
45444545

@@ -4559,8 +4560,8 @@ def refine_identity_comparison_expression(self,
45594560
expr = operands[i]
45604561
expr_type = coerce_to_literal(operand_types[i])
45614562

4562-
if enum_name is not None:
4563-
expr_type = try_expanding_enum_to_union(expr_type, enum_name)
4563+
if sum_type_name is not None:
4564+
expr_type = try_expanding_sum_type_to_union(expr_type, sum_type_name)
45644565

45654566
# We intentionally use 'conditional_type_map' directly here instead of
45664567
# 'self.conditional_type_map_with_intersection': we only compute ad-hoc

mypy/typeops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def is_singleton_type(typ: Type) -> bool:
669669
)
670670

671671

672-
def try_expanding_enum_to_union(typ: Type, target_fullname: str) -> ProperType:
672+
def try_expanding_sum_type_to_union(typ: Type, target_fullname: str) -> ProperType:
673673
"""Attempts to recursively expand any enum Instances with the given target_fullname
674674
into a Union of all of its component LiteralTypes.
675675
@@ -691,7 +691,7 @@ class Status(Enum):
691691
typ = get_proper_type(typ)
692692

693693
if isinstance(typ, UnionType):
694-
items = [try_expanding_enum_to_union(item, target_fullname) for item in typ.items]
694+
items = [try_expanding_sum_type_to_union(item, target_fullname) for item in typ.items]
695695
return make_simplified_union(items, contract_literals=False)
696696
elif isinstance(typ, Instance) and typ.type.fullname == target_fullname:
697697
if typ.type.is_enum:

0 commit comments

Comments
 (0)