[ILibrary.add] respect mutate_other=False even without duplicate keys

This commit is contained in:
Jan Petykiewicz 2026-03-31 23:47:09 -07:00
commit f461222852
2 changed files with 18 additions and 2 deletions

View file

@ -926,8 +926,13 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
duplicates = set(self.keys()) & set(other.keys())
if not duplicates:
for key in other:
self._merge(key, other, key)
if mutate_other:
temp = other
else:
temp = Library(copy.deepcopy(dict(other)))
for key in temp:
self._merge(key, temp, key)
return {}
if mutate_other:

View file

@ -221,6 +221,17 @@ def test_library_rename() -> None:
assert "old" not in lib["parent"].refs
def test_library_add_no_duplicates_respects_mutate_other_false() -> None:
src_pat = Pattern(ports={"A": Port((0, 0), 0)})
lib = Library({"a": Pattern()})
lib.add({"b": src_pat}, mutate_other=False)
assert lib["b"] is not src_pat
lib["b"].ports["A"].offset[0] = 123
assert tuple(src_pat.ports["A"].offset) == (0.0, 0.0)
def test_library_subtree() -> None:
lib = Library()
lib["a"] = Pattern()