diff --git a/masque/__init__.py b/masque/__init__.py index 50ecb7d..2452f33 100644 --- a/masque/__init__.py +++ b/masque/__init__.py @@ -32,7 +32,7 @@ from .error import MasqueError, PatternError, LibraryError, BuildError from .shapes import Shape, Polygon, Path, Circle, Arc, Ellipse from .label import Label from .ref import Ref -from .pattern import Pattern +from .pattern import Pattern, map_layers, map_targets, chain_elements from .library import ( ILibraryView, ILibrary, diff --git a/masque/builder/builder.py b/masque/builder/builder.py index 54ee4d5..0bae1c2 100644 --- a/masque/builder/builder.py +++ b/masque/builder/builder.py @@ -358,35 +358,35 @@ class Builder(PortList): mirrored=mirrored, port_map=map_out, skip_port_check=True, append=append) return self - @overload - def place( - self, - other: Abstract | str, - *, - offset: ArrayLike, - rotation: float, - pivot: ArrayLike, - mirrored: tuple[bool, bool], - port_map: dict[str, str | None] | None, - skip_port_check: bool, - append: bool, - ) -> Self: - pass - - @overload - def place( - self, - other: Pattern, - *, - offset: ArrayLike, - rotation: float, - pivot: ArrayLike, - mirrored: tuple[bool, bool], - port_map: dict[str, str | None] | None, - skip_port_check: bool, - append: Literal[True], - ) -> Self: - pass +# @overload +# def place( +# self, +# other: Abstract | str, +# *, +# offset: ArrayLike, +# rotation: float, +# pivot: ArrayLike, +# mirrored: tuple[bool, bool], +# port_map: dict[str, str | None] | None, +# skip_port_check: bool, +# append: bool, +# ) -> Self: +# pass +# +# @overload +# def place( +# self, +# other: Pattern, +# *, +# offset: ArrayLike, +# rotation: float, +# pivot: ArrayLike, +# mirrored: tuple[bool, bool], +# port_map: dict[str, str | None] | None, +# skip_port_check: bool, +# append: Literal[True], +# ) -> Self: +# pass def place( self, diff --git a/masque/library.py b/masque/library.py index f51d9f9..2f107ed 100644 --- a/masque/library.py +++ b/masque/library.py @@ -575,7 +575,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta): for old_name in temp: new_name = rename_map.get(old_name, old_name) pat = self[new_name] - pat.refs = map_targets(pat.refs, rename_map) + pat.refs = map_targets(pat.refs, lambda tt: cast(dict[str | None, str | None], rename_map).get(tt, tt)) return rename_map diff --git a/masque/pattern.py b/masque/pattern.py index e8770fc..8e68b09 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -779,21 +779,21 @@ def chain_elements(*args: Mapping[Any, Iterable[TT]]) -> Iterable[TT]: def map_layers( elements: Mapping[layer_t, Sequence[TT]], - layer_map: Mapping[layer_t, layer_t], + map_layer: Callable[[layer_t], layer_t], ) -> defaultdict[layer_t, list[TT]]: new_elements: defaultdict[layer_t, list[TT]] = defaultdict(list) for old_layer, seq in elements.items(): - new_layer = layer_map.get(old_layer, old_layer) + new_layer = map_layer(old_layer) new_elements[new_layer].extend(seq) return new_elements def map_targets( refs: Mapping[str | None, Sequence[Ref]], - target_map: Mapping[str | None, str | None] | Mapping[str, str | None], + map_target: Callable[[str | None], str | None], ) -> defaultdict[str | None, list[Ref]]: new_refs: defaultdict[str | None, list[Ref]] = defaultdict(list) for old_target, seq in refs.items(): - new_target = target_map.get(old_target, old_target) # type: ignore # OK to .get() wrong type + new_target = map_target(old_target) new_refs[new_target].extend(seq) return new_refs