From bb7f4906af0612c7d84aee58e59d44f62ab01d9d Mon Sep 17 00:00:00 2001 From: jan Date: Sat, 7 Mar 2026 23:35:47 -0800 Subject: [PATCH] [ILibrary] add .resolve() --- masque/library.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/masque/library.py b/masque/library.py index 3e1c65c..1240b48 100644 --- a/masque/library.py +++ b/masque/library.py @@ -682,6 +682,33 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta): def _merge(self, key_self: str, other: Mapping[str, 'Pattern'], key_other: str) -> None: pass + def resolve( + self, + other: 'Abstract | str | Pattern | TreeView', + append: bool = False, + ) -> 'Abstract | Pattern': + """ + Resolve another device (name, Abstract, Pattern, or TreeView) into an Abstract or Pattern. + If it is a TreeView, it is first added into this library. + + Args: + other: The device to resolve. + append: If True and `other` is an `Abstract`, returns the full `Pattern` from the library. + + Returns: + An `Abstract` or `Pattern` object. + """ + from .pattern import Pattern #noqa: PLC0415 + if not isinstance(other, (str, Abstract, Pattern)): + # We got a TreeView; add it into self and grab its topcell as an Abstract + other = self << other + + if isinstance(other, str): + other = self.abstract(other) + if append and isinstance(other, Abstract): + other = self[other.name] + return other + def rename( self, old_name: str,