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

Use dict keys for order-preserving dedupes instead of set + list #15105

Merged
merged 8 commits into from
Apr 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions mypyc/ir/rtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,17 +820,11 @@ def make_simplified_union(items: list[RType]) -> RType:
items = flatten_nested_unions(items)
assert items

# Remove duplicate items using set + list to preserve item order
seen = set()
new_items = []
for item in items:
if item not in seen:
new_items.append(item)
seen.add(item)
if len(new_items) > 1:
return RUnion(new_items)
unique_items = dict.fromkeys(items)
if len(unique_items) > 1:
return RUnion(list(unique_items))
else:
return new_items[0]
return next(iter(unique_items))

def accept(self, visitor: RTypeVisitor[T]) -> T:
return visitor.visit_runion(self)
Expand Down