Skip to content

Commit 536be1c

Browse files
committed
Rename expansion-related locals/functions
No longer only works on enums
1 parent df63e3b commit 536be1c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

mypy/checker.py

+5-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
)
@@ -4534,11 +4534,11 @@ def refine_identity_comparison_expression(self,
45344534
if singleton_index == -1:
45354535
singleton_index = possible_target_indices[-1]
45364536

4537-
enum_name = None
4537+
sum_type_name = None
45384538
target = get_proper_type(target)
45394539
if (isinstance(target, LiteralType) and
45404540
(target.is_enum_literal() or isinstance(target.value, bool))):
4541-
enum_name = target.fallback.type.fullname
4541+
sum_type_name = target.fallback.type.fullname
45424542

45434543
target_type = [TypeRange(target, is_upper_bound=False)]
45444544

@@ -4559,8 +4559,8 @@ def refine_identity_comparison_expression(self,
45594559
expr = operands[i]
45604560
expr_type = coerce_to_literal(operand_types[i])
45614561

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

45654565
# We intentionally use 'conditional_type_map' directly here instead of
45664566
# '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)