misc fixes
This commit is contained in:
parent
88d123af71
commit
152dea9b60
@ -32,7 +32,7 @@ from .error import MasqueError, PatternError, LibraryError, BuildError
|
|||||||
from .shapes import Shape, Polygon, Path, Circle, Arc, Ellipse
|
from .shapes import Shape, Polygon, Path, Circle, Arc, Ellipse
|
||||||
from .label import Label
|
from .label import Label
|
||||||
from .ref import Ref
|
from .ref import Ref
|
||||||
from .pattern import Pattern
|
from .pattern import Pattern, map_layers, map_targets, chain_elements
|
||||||
|
|
||||||
from .library import (
|
from .library import (
|
||||||
ILibraryView, ILibrary,
|
ILibraryView, ILibrary,
|
||||||
|
@ -358,35 +358,35 @@ class Builder(PortList):
|
|||||||
mirrored=mirrored, port_map=map_out, skip_port_check=True, append=append)
|
mirrored=mirrored, port_map=map_out, skip_port_check=True, append=append)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@overload
|
# @overload
|
||||||
def place(
|
# def place(
|
||||||
self,
|
# self,
|
||||||
other: Abstract | str,
|
# other: Abstract | str,
|
||||||
*,
|
# *,
|
||||||
offset: ArrayLike,
|
# offset: ArrayLike,
|
||||||
rotation: float,
|
# rotation: float,
|
||||||
pivot: ArrayLike,
|
# pivot: ArrayLike,
|
||||||
mirrored: tuple[bool, bool],
|
# mirrored: tuple[bool, bool],
|
||||||
port_map: dict[str, str | None] | None,
|
# port_map: dict[str, str | None] | None,
|
||||||
skip_port_check: bool,
|
# skip_port_check: bool,
|
||||||
append: bool,
|
# append: bool,
|
||||||
) -> Self:
|
# ) -> Self:
|
||||||
pass
|
# pass
|
||||||
|
#
|
||||||
@overload
|
# @overload
|
||||||
def place(
|
# def place(
|
||||||
self,
|
# self,
|
||||||
other: Pattern,
|
# other: Pattern,
|
||||||
*,
|
# *,
|
||||||
offset: ArrayLike,
|
# offset: ArrayLike,
|
||||||
rotation: float,
|
# rotation: float,
|
||||||
pivot: ArrayLike,
|
# pivot: ArrayLike,
|
||||||
mirrored: tuple[bool, bool],
|
# mirrored: tuple[bool, bool],
|
||||||
port_map: dict[str, str | None] | None,
|
# port_map: dict[str, str | None] | None,
|
||||||
skip_port_check: bool,
|
# skip_port_check: bool,
|
||||||
append: Literal[True],
|
# append: Literal[True],
|
||||||
) -> Self:
|
# ) -> Self:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def place(
|
def place(
|
||||||
self,
|
self,
|
||||||
|
@ -575,7 +575,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
|
|||||||
for old_name in temp:
|
for old_name in temp:
|
||||||
new_name = rename_map.get(old_name, old_name)
|
new_name = rename_map.get(old_name, old_name)
|
||||||
pat = self[new_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
|
return rename_map
|
||||||
|
|
||||||
|
@ -779,21 +779,21 @@ def chain_elements(*args: Mapping[Any, Iterable[TT]]) -> Iterable[TT]:
|
|||||||
|
|
||||||
def map_layers(
|
def map_layers(
|
||||||
elements: Mapping[layer_t, Sequence[TT]],
|
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]]:
|
) -> defaultdict[layer_t, list[TT]]:
|
||||||
new_elements: defaultdict[layer_t, list[TT]] = defaultdict(list)
|
new_elements: defaultdict[layer_t, list[TT]] = defaultdict(list)
|
||||||
for old_layer, seq in elements.items():
|
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)
|
new_elements[new_layer].extend(seq)
|
||||||
return new_elements
|
return new_elements
|
||||||
|
|
||||||
|
|
||||||
def map_targets(
|
def map_targets(
|
||||||
refs: Mapping[str | None, Sequence[Ref]],
|
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]]:
|
) -> defaultdict[str | None, list[Ref]]:
|
||||||
new_refs: defaultdict[str | None, list[Ref]] = defaultdict(list)
|
new_refs: defaultdict[str | None, list[Ref]] = defaultdict(list)
|
||||||
for old_target, seq in refs.items():
|
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)
|
new_refs[new_target].extend(seq)
|
||||||
return new_refs
|
return new_refs
|
||||||
|
Loading…
Reference in New Issue
Block a user