Skip to content

Commit

Permalink
fix: cleanup empty containers and namespaces after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Nov 5, 2021
1 parent 1acc57a commit 43b7d08
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions beet/library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,14 @@ def merge(
other: Mapping[T, MergeableType],
) -> bool:
super().merge(other) # type: ignore

if isinstance(self, Namespace) and isinstance(other, Namespace):
self.extra.merge(other.extra)

empty_containers = [key for key, value in self.items() if not value] # type: ignore
for container in empty_containers:
del self[container] # type: ignore

return True

@property
Expand Down Expand Up @@ -746,8 +752,14 @@ def merge(
self: MutableMapping[T, MergeableType], other: Mapping[T, MergeableType]
) -> bool:
super().merge(other) # type: ignore

if isinstance(self, Pack) and isinstance(other, Pack):
self.extra.merge(other.extra) # type: ignore

empty_namespaces = [key for key, value in self.items() if not value] # type: ignore
for namespace in empty_namespaces:
del self[namespace] # type: ignore

return True

@property
Expand Down

0 comments on commit 43b7d08

Please sign in to comment.