8000 Fix performance in union subtyping (#15104) · python/mypy@d887e9c · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d887e9c

Browse files
hauntsaninjawesleywright
authored andcommitted
Fix performance in union subtyping (#15104)
This is a performance optimisation for subtyping between two unions that are largely the same. Fixes #14034 This makes @adriangb's example in #14034 (comment) finish basically instantly. I could add it as a unit test? Type checking pydantic core is still not fast — takes like four or five minutes with uncompiled mypy — but at least it's now feasible. I think there's room for doing some optimisation in make_simplified_union that would improve this.
1 parent 320b883 commit d887e9c

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

mypy/subtypes.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -917,13 +917,9 @@ def visit_union_type(self, left: UnionType) -> bool:
917917

918918
for item in _flattened(self.right.relevant_items()):
919919
p_item = get_proper_type(item)
920-
if isinstance(p_item, LiteralType):
921-
fast_check.add(p_item)
922-
elif isinstance(p_item, Instance):
923-
if p_item.last_known_value is None:
924-
fast_check.add(p_item)
925-
else:
926-
fast_check.add(p_item.last_known_value)
920+
fast_check.add(p_item)
921+
if isinstance(p_item, Instance) and p_item.last_known_value is not None:
922+
fast_check.add(p_item.last_known_value)
927923

928924
for item in left.relevant_items():
929925
p_item = get_proper_type(item)

0 commit comments

Comments
 (0)
0