Drop ports by default

This commit is contained in:
Jan Petykiewicz 2023-02-08 09:26:44 -08:00
parent 38a7ba6434
commit 1d720b6577
2 changed files with 6 additions and 0 deletions

View File

@ -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()

View File

@ -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()