Skip to content

Commit 9e7a695

Browse files
ethan-lebaEthan Leba
authored andcommitted
Rename expansion-related locals/functions
No longer only works on enums
1 parent ac3f313 commit 9e7a695

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

mypy/checker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
map_type_from_supertype, bind_self, erase_to_bound, make_simplified_union,
5151
erase_def_to_union_or_bound, erase_to_union_or_bound, coerce_to_literal,
5252
try_getting_str_literals_from_type, try_getting_int_literals_from_type,
53-
tuple_fallback, is_singleton_type, try_expanding_enum_to_union,
53+
tuple_fallback, is_singleton_type, try_expanding_sum_type_to_union,
5454
true_only, false_only, function_type, get_type_vars, custom_special_method,
5555
is_literal_type_like,
5656
)
@@ -4612,11 +4612,11 @@ def refine_identity_comparison_expression(self,
46124612
if singleton_index == -1:
46134613
singleton_index = possible_target_indices[-1]
46144614

4615-
enum_name = None
4615+
sum_type_name = None
46164616
target = get_proper_type(target)
46174617
if (isinstance(target, LiteralType) and
46184618
(target.is_enum_literal() or isinstance(target.value, bool))):
4619-
enum_name = target.fallback.type.fullname
4619+
sum_type_name = target.fallback.type.fullname
46204620

46214621
target_type = [TypeRange(target, is_upper_bound=False)]
46224622

@@ -4637,8 +4637,8 @@ def refine_identity_comparison_expression(self,
46374637
expr = operands[i]
46384638
expr_type = coerce_to_literal(operand_types[i])
46394639

4640-
if enum_name is not None:
4641-
expr_type = try_expanding_enum_to_union(expr_type, enum_name)
4640+
if sum_type_name is not None:
4641+
expr_type = try_expanding_sum_type_to_union(expr_type, sum_type_name)
46424642

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

mypy/typeops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ def is_singleton_type(typ: Type) -> bool:
699699
)
700700

701701

702-
def try_expanding_enum_to_union(typ: Type, target_fullname: str) -> ProperType:
702+
def try_expanding_sum_type_to_union(typ: Type, target_fullname: str) -> ProperType:
703703
"""Attempts to recursively expand any enum Instances with the given target_fullname
704704
into a Union of all of its component LiteralTypes.
705705
@@ -721,7 +721,7 @@ class Status(Enum):
721721
typ = get_proper_type(typ)
722722

723723
if isinstance(typ, UnionType):
724-
items = [try_expanding_enum_to_union(item, target_fullname) for item in typ.items]
724+
items = [try_expanding_sum_type_to_union(item, target_fullname) for item in typ.items]
725725
return make_simplified_union(items, contract_literals=False)
726726
elif isinstance(typ, Instance) and typ.type.fullname == target_fullname:
727727
if typ.type.is_enum:

0 commit comments

Comments
 (0)