type annotation updates
This commit is contained in:
parent
3d50ff0070
commit
9d5b1ef5e6
@ -138,7 +138,7 @@ class Builder(PortList):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def interface(
|
def interface(
|
||||||
cls,
|
cls: type['Builder'],
|
||||||
source: PortList | Mapping[str, Port] | str,
|
source: PortList | Mapping[str, Port] | str,
|
||||||
*,
|
*,
|
||||||
library: ILibrary | None = None,
|
library: ILibrary | None = None,
|
||||||
@ -276,7 +276,7 @@ class Builder(PortList):
|
|||||||
logger.error('Skipping plug() since device is dead')
|
logger.error('Skipping plug() since device is dead')
|
||||||
return self
|
return self
|
||||||
|
|
||||||
if not isinstance(other, (str, Abstract, Pattern)):
|
if not isinstance(other, str | Abstract | Pattern):
|
||||||
# We got a Tree; add it into self.library and grab an Abstract for it
|
# We got a Tree; add it into self.library and grab an Abstract for it
|
||||||
other = self.library << other
|
other = self.library << other
|
||||||
|
|
||||||
@ -348,7 +348,7 @@ class Builder(PortList):
|
|||||||
logger.error('Skipping place() since device is dead')
|
logger.error('Skipping place() since device is dead')
|
||||||
return self
|
return self
|
||||||
|
|
||||||
if not isinstance(other, (str, Abstract, Pattern)):
|
if not isinstance(other, str | Abstract | Pattern):
|
||||||
# We got a Tree; add it into self.library and grab an Abstract for it
|
# We got a Tree; add it into self.library and grab an Abstract for it
|
||||||
other = self.library << other
|
other = self.library << other
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ class Pather(Builder):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_builder(
|
def from_builder(
|
||||||
cls,
|
cls: type['Pather'],
|
||||||
builder: Builder,
|
builder: Builder,
|
||||||
*,
|
*,
|
||||||
tools: Tool | MutableMapping[str | None, Tool] | None = None,
|
tools: Tool | MutableMapping[str | None, Tool] | None = None,
|
||||||
@ -195,7 +195,7 @@ class Pather(Builder):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def interface(
|
def interface(
|
||||||
cls,
|
cls: type['Pather'],
|
||||||
source: PortList | Mapping[str, Port] | str,
|
source: PortList | Mapping[str, Port] | str,
|
||||||
*,
|
*,
|
||||||
library: ILibrary | None = None,
|
library: ILibrary | None = None,
|
||||||
|
@ -128,7 +128,7 @@ class RenderPather(PortList):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def interface(
|
def interface(
|
||||||
cls,
|
cls: type['RenderPather'],
|
||||||
source: PortList | Mapping[str, Port] | str,
|
source: PortList | Mapping[str, Port] | str,
|
||||||
*,
|
*,
|
||||||
library: ILibrary | None = None,
|
library: ILibrary | None = None,
|
||||||
|
@ -693,9 +693,9 @@ def properties_to_annotations(
|
|||||||
|
|
||||||
assert proprec.values is not None
|
assert proprec.values is not None
|
||||||
for value in proprec.values:
|
for value in proprec.values:
|
||||||
if isinstance(value, (float, int)):
|
if isinstance(value, float | int):
|
||||||
values.append(value)
|
values.append(value)
|
||||||
elif isinstance(value, (NString, AString)):
|
elif isinstance(value, NString | AString):
|
||||||
values.append(value.string)
|
values.append(value.string)
|
||||||
elif isinstance(value, PropStringReference):
|
elif isinstance(value, PropStringReference):
|
||||||
values.append(propstrings[value.ref].string) # dereference
|
values.append(propstrings[value.ref].string) # dereference
|
||||||
|
@ -117,7 +117,7 @@ def clean_pattern_vertices(pat: Pattern) -> Pattern:
|
|||||||
for shapes in pat.shapes.values():
|
for shapes in pat.shapes.values():
|
||||||
remove_inds = []
|
remove_inds = []
|
||||||
for ii, shape in enumerate(shapes):
|
for ii, shape in enumerate(shapes):
|
||||||
if not isinstance(shape, (Polygon, Path)):
|
if not isinstance(shape, Polygon | Path):
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
shape.clean_vertices()
|
shape.clean_vertices()
|
||||||
|
@ -14,7 +14,7 @@ Classes include:
|
|||||||
- `AbstractView`: Provides a way to use []-indexing to generate abstracts for patterns in the linked
|
- `AbstractView`: Provides a way to use []-indexing to generate abstracts for patterns in the linked
|
||||||
library. Generated with `ILibraryView.abstract_view()`.
|
library. Generated with `ILibraryView.abstract_view()`.
|
||||||
"""
|
"""
|
||||||
from typing import Callable, Self, Type, TYPE_CHECKING, cast, TypeAlias, Protocol, Literal
|
from typing import Self, TYPE_CHECKING, cast, TypeAlias, Protocol, Literal
|
||||||
from collections.abc import Iterator, Mapping, MutableMapping, Sequence, Callable
|
from collections.abc import Iterator, Mapping, MutableMapping, Sequence, Callable
|
||||||
import logging
|
import logging
|
||||||
import base64
|
import base64
|
||||||
@ -285,7 +285,7 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta):
|
|||||||
if isinstance(tops, str):
|
if isinstance(tops, str):
|
||||||
tops = (tops,)
|
tops = (tops,)
|
||||||
|
|
||||||
flattened: dict[str, 'Pattern | None'] = {}
|
flattened: dict[str, Pattern | None] = {}
|
||||||
|
|
||||||
def flatten_single(name: str) -> None:
|
def flatten_single(name: str) -> None:
|
||||||
flattened[name] = None
|
flattened[name] = None
|
||||||
@ -735,7 +735,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
|
|||||||
def dedup(
|
def dedup(
|
||||||
self,
|
self,
|
||||||
norm_value: int = int(1e6),
|
norm_value: int = int(1e6),
|
||||||
exclude_types: tuple[Type] = (Polygon,),
|
exclude_types: tuple[type] = (Polygon,),
|
||||||
label2name: Callable[[tuple], str] | None = None,
|
label2name: Callable[[tuple], str] | None = None,
|
||||||
threshold: int = 2,
|
threshold: int = 2,
|
||||||
) -> Self:
|
) -> Self:
|
||||||
@ -773,7 +773,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
|
|||||||
exclude_types = ()
|
exclude_types = ()
|
||||||
|
|
||||||
if label2name is None:
|
if label2name is None:
|
||||||
def label2name(label):
|
def label2name(label: tuple) -> str: # noqa: ARG001
|
||||||
return self.get_name(SINGLE_USE_PREFIX + 'shape')
|
return self.get_name(SINGLE_USE_PREFIX + 'shape')
|
||||||
|
|
||||||
shape_counts: MutableMapping[tuple, int] = defaultdict(int)
|
shape_counts: MutableMapping[tuple, int] = defaultdict(int)
|
||||||
@ -863,7 +863,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
|
|||||||
from .pattern import Pattern
|
from .pattern import Pattern
|
||||||
|
|
||||||
if name_func is None:
|
if name_func is None:
|
||||||
def name_func(_pat, _shape):
|
def name_func(_pat: Pattern, _shape: Shape | Label) -> str:
|
||||||
return self.get_name(SINGLE_USE_PREFIX + 'rep')
|
return self.get_name(SINGLE_USE_PREFIX + 'rep')
|
||||||
|
|
||||||
for pat in tuple(self.values()):
|
for pat in tuple(self.values()):
|
||||||
@ -1054,7 +1054,7 @@ class Library(ILibrary):
|
|||||||
return f'<Library ({type(self.mapping)}) with keys\n' + pformat(list(self.keys())) + '>'
|
return f'<Library ({type(self.mapping)}) with keys\n' + pformat(list(self.keys())) + '>'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def mktree(cls, name: str) -> tuple[Self, 'Pattern']:
|
def mktree(cls: type[Self], name: str) -> tuple[Self, 'Pattern']:
|
||||||
"""
|
"""
|
||||||
Create a new Library and immediately add a pattern
|
Create a new Library and immediately add a pattern
|
||||||
|
|
||||||
|
@ -1325,7 +1325,7 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def interface(
|
def interface(
|
||||||
cls,
|
cls: type['Pattern'],
|
||||||
source: PortList | Mapping[str, Port],
|
source: PortList | Mapping[str, Port],
|
||||||
*,
|
*,
|
||||||
in_prefix: str = 'in_',
|
in_prefix: str = 'in_',
|
||||||
|
@ -93,7 +93,7 @@ class Port(PositionableImpl, Rotatable, PivotableImpl, Copyable, Mirrorable):
|
|||||||
def copy(self) -> Self:
|
def copy(self) -> Self:
|
||||||
return self.deepcopy()
|
return self.deepcopy()
|
||||||
|
|
||||||
def get_bounds(self):
|
def get_bounds(self) -> NDArray[numpy.float64]:
|
||||||
return numpy.vstack((self.offset, self.offset))
|
return numpy.vstack((self.offset, self.offset))
|
||||||
|
|
||||||
def set_ptype(self, ptype: str) -> Self:
|
def set_ptype(self, ptype: str) -> Self:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Repetitions provide support for efficiently representing multiple identical
|
Repetitions provide support for efficiently representing multiple identical
|
||||||
instances of an object .
|
instances of an object .
|
||||||
"""
|
"""
|
||||||
from typing import Any, Type, Self, TypeVar, cast
|
from typing import Any, Self, TypeVar, cast
|
||||||
import copy
|
import copy
|
||||||
import functools
|
import functools
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
@ -116,7 +116,7 @@ class Grid(Repetition):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def aligned(
|
def aligned(
|
||||||
cls: Type[GG],
|
cls: type[GG],
|
||||||
x: float,
|
x: float,
|
||||||
y: float,
|
y: float,
|
||||||
x_count: int,
|
x_count: int,
|
||||||
|
@ -130,7 +130,7 @@ class Circle(Shape):
|
|||||||
self.radius *= c
|
self.radius *= c
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def normalized_form(self, norm_value) -> normalized_shape_tuple:
|
def normalized_form(self, norm_value: float) -> normalized_shape_tuple:
|
||||||
rotation = 0.0
|
rotation = 0.0
|
||||||
magnitude = self.radius / norm_value
|
magnitude = self.radius / norm_value
|
||||||
return ((type(self),),
|
return ((type(self),),
|
||||||
|
@ -63,7 +63,7 @@ class LayerableImpl(Layerable, metaclass=ABCMeta):
|
|||||||
return self._layer
|
return self._layer
|
||||||
|
|
||||||
@layer.setter
|
@layer.setter
|
||||||
def layer(self, val: layer_t):
|
def layer(self, val: layer_t) -> None:
|
||||||
self._layer = val
|
self._layer = val
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -44,7 +44,7 @@ class Mirrorable(metaclass=ABCMeta):
|
|||||||
# """
|
# """
|
||||||
# __slots__ = ()
|
# __slots__ = ()
|
||||||
#
|
#
|
||||||
# _mirrored: numpy.ndarray # ndarray[bool]
|
# _mirrored: NDArray[numpy.bool]
|
||||||
# """ Whether to mirror the instance across the x and/or y axes. """
|
# """ Whether to mirror the instance across the x and/or y axes. """
|
||||||
#
|
#
|
||||||
# #
|
# #
|
||||||
@ -52,12 +52,12 @@ class Mirrorable(metaclass=ABCMeta):
|
|||||||
# #
|
# #
|
||||||
# # Mirrored property
|
# # Mirrored property
|
||||||
# @property
|
# @property
|
||||||
# def mirrored(self) -> numpy.ndarray: # ndarray[bool]
|
# def mirrored(self) -> NDArray[numpy.bool]:
|
||||||
# """ Whether to mirror across the [x, y] axes, respectively """
|
# """ Whether to mirror across the [x, y] axes, respectively """
|
||||||
# return self._mirrored
|
# return self._mirrored
|
||||||
#
|
#
|
||||||
# @mirrored.setter
|
# @mirrored.setter
|
||||||
# def mirrored(self, val: Sequence[bool]):
|
# def mirrored(self, val: Sequence[bool]) -> None:
|
||||||
# if is_scalar(val):
|
# if is_scalar(val):
|
||||||
# raise MasqueError('Mirrored must be a 2-element list of booleans')
|
# raise MasqueError('Mirrored must be a 2-element list of booleans')
|
||||||
# self._mirrored = numpy.array(val, dtype=bool, copy=True)
|
# self._mirrored = numpy.array(val, dtype=bool, copy=True)
|
||||||
|
@ -34,7 +34,7 @@ class Repeatable(metaclass=ABCMeta):
|
|||||||
|
|
||||||
# @repetition.setter
|
# @repetition.setter
|
||||||
# @abstractmethod
|
# @abstractmethod
|
||||||
# def repetition(self, repetition: 'Repetition | None'):
|
# def repetition(self, repetition: 'Repetition | None') -> None:
|
||||||
# pass
|
# pass
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -75,7 +75,7 @@ class RepeatableImpl(Repeatable, Bounded, metaclass=ABCMeta):
|
|||||||
return self._repetition
|
return self._repetition
|
||||||
|
|
||||||
@repetition.setter
|
@repetition.setter
|
||||||
def repetition(self, repetition: 'Repetition | None'):
|
def repetition(self, repetition: 'Repetition | None') -> None:
|
||||||
from ..repetition import Repetition
|
from ..repetition import Repetition
|
||||||
if repetition is not None and not isinstance(repetition, Repetition):
|
if repetition is not None and not isinstance(repetition, Repetition):
|
||||||
raise MasqueError(f'{repetition} is not a valid Repetition object!')
|
raise MasqueError(f'{repetition} is not a valid Repetition object!')
|
||||||
|
@ -54,7 +54,7 @@ class RotatableImpl(Rotatable, metaclass=ABCMeta):
|
|||||||
return self._rotation
|
return self._rotation
|
||||||
|
|
||||||
@rotation.setter
|
@rotation.setter
|
||||||
def rotation(self, val: float):
|
def rotation(self, val: float) -> None:
|
||||||
if not numpy.size(val) == 1:
|
if not numpy.size(val) == 1:
|
||||||
raise MasqueError('Rotation must be a scalar')
|
raise MasqueError('Rotation must be a scalar')
|
||||||
self._rotation = val % (2 * pi)
|
self._rotation = val % (2 * pi)
|
||||||
|
@ -48,7 +48,7 @@ class ScalableImpl(Scalable, metaclass=ABCMeta):
|
|||||||
return self._scale
|
return self._scale
|
||||||
|
|
||||||
@scale.setter
|
@scale.setter
|
||||||
def scale(self, val: float):
|
def scale(self, val: float) -> None:
|
||||||
if not is_scalar(val):
|
if not is_scalar(val):
|
||||||
raise MasqueError('Scale must be a scalar')
|
raise MasqueError('Scale must be a scalar')
|
||||||
if not val > 0:
|
if not val > 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user