misc fixes
This commit is contained in:
parent
9a077ea2df
commit
93ab0a942d
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user