in usort/types.py [0:0]
def __add__(self, other: "SortableImport") -> "SortableImport":
if not isinstance(other, SortableImport):
return NotImplemented
if self.sort_key != other.sort_key and self.stem != other.stem:
raise ValueError("sort_key and stem must match")
# Combine the items from the other import statement with items from this import.
# If both the name and asname match, we can safely just add-op them to combine
# comments, and assume the other import object will get discarded. If there is
# no match, new items from other will be appended to the end of the list.
#
# from foo import a, b, c
# from foo import b, c as C, d
#
# should get combined to
#
# from foo import a, b, c, c as C, d
#
combined_items = list(self.items)
for item in other.items:
if item in combined_items:
idx = combined_items.index(item)
combined_items[idx] += item
else:
combined_items.append(item)
return SortableImport(
stem=self.stem,
items=combined_items,
comments=self.comments + other.comments,
indent=self.indent,
config=self.config,
node=self.node,
)