From 1d720b6577da884f0d2752ed665f6042e30f632f Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Wed, 8 Feb 2023 09:26:44 -0800 Subject: [PATCH] Drop ports by default --- masque/library.py | 3 +++ masque/pattern.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/masque/library.py b/masque/library.py index c7e3f88..99a43f5 100644 --- a/masque/library.py +++ b/masque/library.py @@ -207,6 +207,7 @@ class Library(Mapping[str, 'Pattern'], metaclass=ABCMeta): def flatten( self, tops: Union[str, Sequence[str]], + flatten_ports: bool = False, # TODO document ) -> Dict[str, 'Pattern']: """ Removes all refs and adds equivalent shapes. @@ -238,6 +239,8 @@ class Library(Mapping[str, 'Pattern'], metaclass=ABCMeta): raise PatternError(f'Circular reference in {name} to {target}') p = ref.as_pattern(pattern=flattened[target]) + if not flatten_ports: + p.ports.clear() pat.append(p) pat.refs.clear() diff --git a/masque/pattern.py b/masque/pattern.py index f624b73..c9d40fb 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -561,6 +561,7 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable): def flatten( self: P, library: Mapping[str, P], + flatten_ports: bool = False, # TODO document ) -> 'Pattern': """ Removes all refs (recursively) and adds equivalent shapes. @@ -592,6 +593,8 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable): raise PatternError(f'Circular reference in {name} to {target}') p = ref.as_pattern(pattern=flattened[target]) + if not flatten_ports: + p.ports.clear() pat.append(p) pat.refs.clear()