From b44c962e079882f119a6b524660349134fa1ae63 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 30 Mar 2026 22:11:50 -0700 Subject: [PATCH] [Pattern] improve error handling in place() --- masque/pattern.py | 4 +++- masque/test/test_pattern.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/masque/pattern.py b/masque/pattern.py index 0a66aee..ab5f55a 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -1411,7 +1411,9 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable): other_copy.translate_elements(offset) self.append(other_copy) else: - assert not isinstance(other, Pattern) + if isinstance(other, Pattern): + raise PatternError('Must provide an `Abstract` (not a `Pattern`) when creating a reference. ' + 'Use `append=True` if you intended to append the full geometry.') ref = Ref(mirrored=mirrored) ref.rotate_around(pivot, rotation) ref.translate(offset) diff --git a/masque/test/test_pattern.py b/masque/test/test_pattern.py index b459502..07e4150 100644 --- a/masque/test/test_pattern.py +++ b/masque/test/test_pattern.py @@ -126,6 +126,14 @@ def test_pattern_flatten_repeated_ref_with_ports_raises() -> None: parent.flatten({"child": child}, flatten_ports=True) +def test_pattern_place_requires_abstract_for_reference() -> None: + parent = Pattern() + child = Pattern() + + with pytest.raises(PatternError, match='Must provide an `Abstract`'): + parent.place(child) + + def test_pattern_interface() -> None: source = Pattern() source.ports["A"] = Port((10, 20), 0, ptype="test")