Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix self-check (and therefore mypyc) on older Python versions #7176

Merged
merged 2 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4545,9 +4545,8 @@ class Status(Enum):
this function will return Literal[Color.RED, Color.BLUE, Color.YELLOW, Status].
"""
if isinstance(typ, UnionType):
new_items = [try_expanding_enum_to_union(item, target_fullname)
for item in typ.items]
return UnionType.make_simplified_union(new_items)
items = [try_expanding_enum_to_union(item, target_fullname) for item in typ.items]
return UnionType.make_simplified_union(items)
elif isinstance(typ, Instance) and typ.type.is_enum and typ.type.fullname() == target_fullname:
new_items = []
for name, symbol in typ.type.names.items():
Expand Down
5 changes: 3 additions & 2 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ def make_union(items: List[Type], line: int = -1, column: int = -1) -> Type:
return UninhabitedType()

@staticmethod
def make_simplified_union(items: List[Type], line: int = -1, column: int = -1) -> Type:
def make_simplified_union(items: Sequence[Type], line: int = -1, column: int = -1) -> Type:
"""Build union type with redundant union items removed.

If only a single item remains, this may return a non-union type.
Expand All @@ -1623,6 +1623,7 @@ def make_simplified_union(items: List[Type], line: int = -1, column: int = -1) -
"""
# TODO: Make this a function living somewhere outside mypy.types. Most other non-trivial
# type operations are not static methods, so this is inconsistent.
items = list(items)
while any(isinstance(typ, UnionType) for typ in items):
all_items = [] # type: List[Type]
for typ in items:
Expand All @@ -1640,7 +1641,7 @@ def make_simplified_union(items: List[Type], line: int = -1, column: int = -1) -
# Keep track of the truishness info for deleted subtypes which can be relevant
cbt = cbf = False
for j, tj in enumerate(items):
if (i != j and is_proper_subtype(tj, ti)):
if i != j and is_proper_subtype(tj, ti):
# We found a redundant item in the union.
removed.add(j)
cbt = cbt or tj.can_be_true
Expand Down