Skip to content

Commit

Permalink
Fix performance in union subtyping
Browse files Browse the repository at this point in the history
This is a performance optimisation for subtyping between two unions that
are largely the same.

Fixes python#14034
  • Loading branch information
hauntsaninja committed Apr 23, 2023
1 parent 3cca987 commit d89b317
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,13 +917,9 @@ def visit_union_type(self, left: UnionType) -> bool:

for item in _flattened(self.right.relevant_items()):
p_item = get_proper_type(item)
if isinstance(p_item, LiteralType):
fast_check.add(p_item)
elif isinstance(p_item, Instance):
if p_item.last_known_value is None:
fast_check.add(p_item)
else:
fast_check.add(p_item.last_known_value)
fast_check.add(p_item)
if isinstance(p_item, Instance) and p_item.last_known_value is not None:
fast_check.add(p_item.last_known_value)

for item in left.relevant_items():
p_item = get_proper_type(item)
Expand Down

0 comments on commit d89b317

Please sign in to comment.