modernize type annotations
This commit is contained in:
parent
ada8c591a0
commit
1463535676
5 changed files with 409 additions and 444 deletions
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
2D bin-packing
|
||||
"""
|
||||
from typing import Tuple, List, Set, Sequence, Callable, Mapping
|
||||
from typing import Sequence, Callable, Mapping
|
||||
|
||||
import numpy
|
||||
from numpy.typing import NDArray, ArrayLike
|
||||
|
|
@ -16,7 +16,7 @@ def maxrects_bssf(
|
|||
containers: ArrayLike,
|
||||
presort: bool = True,
|
||||
allow_rejects: bool = True,
|
||||
) -> Tuple[NDArray[numpy.float64], Set[int]]:
|
||||
) -> tuple[NDArray[numpy.float64], set[int]]:
|
||||
"""
|
||||
sizes should be Nx2
|
||||
regions should be Mx4 (xmin, ymin, xmax, ymax)
|
||||
|
|
@ -88,7 +88,7 @@ def guillotine_bssf_sas(rect_sizes: numpy.ndarray,
|
|||
regions: numpy.ndarray,
|
||||
presort: bool = True,
|
||||
allow_rejects: bool = True,
|
||||
) -> Tuple[numpy.ndarray, Set[int]]:
|
||||
) -> tuple[numpy.ndarray, set[int]]:
|
||||
"""
|
||||
sizes should be Nx2
|
||||
regions should be Mx4 (xmin, ymin, xmax, ymax)
|
||||
|
|
@ -146,11 +146,11 @@ def pack_patterns(
|
|||
library: Mapping[str, Pattern],
|
||||
patterns: Sequence[str],
|
||||
regions: numpy.ndarray,
|
||||
spacing: Tuple[float, float],
|
||||
spacing: tuple[float, float],
|
||||
presort: bool = True,
|
||||
allow_rejects: bool = True,
|
||||
packer: Callable = maxrects_bssf,
|
||||
) -> Tuple[Pattern, List[str]]:
|
||||
) -> tuple[Pattern, list[str]]:
|
||||
half_spacing = numpy.array(spacing) / 2
|
||||
|
||||
bounds = [library[pp].get_bounds() for pp in patterns]
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ and retrieving it (`data_to_ports`).
|
|||
the port locations. This particular approach is just a sensible default; feel free to
|
||||
to write equivalent functions for your own format or alternate storage methods.
|
||||
"""
|
||||
from typing import Sequence, Optional, Mapping
|
||||
from typing import Sequence, Mapping
|
||||
import logging
|
||||
|
||||
import numpy
|
||||
|
|
@ -56,7 +56,7 @@ def data_to_ports(
|
|||
pattern: Pattern, # Pattern is good since we don't want to do library[name] to avoid infinite recursion.
|
||||
# LazyLibrary protects against library[ref.target] causing a circular lookup.
|
||||
# For others, maybe check for cycles up front? TODO
|
||||
name: Optional[str] = None, # Note: name optional, but arg order different from read(postprocess=)
|
||||
name: str | None = None, # Note: name optional, but arg order different from read(postprocess=)
|
||||
max_depth: int = 0,
|
||||
skip_subcells: bool = True,
|
||||
# TODO missing ok?
|
||||
|
|
@ -130,7 +130,7 @@ def data_to_ports(
|
|||
def data_to_ports_flat(
|
||||
layers: Sequence[layer_t],
|
||||
pattern: Pattern,
|
||||
cell_name: Optional[str] = None,
|
||||
cell_name: str | None = None,
|
||||
) -> Pattern:
|
||||
"""
|
||||
Examine `pattern` for labels specifying port info, and use that info
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
Geometric transforms
|
||||
"""
|
||||
from typing import Sequence, Tuple
|
||||
from typing import Sequence
|
||||
|
||||
import numpy
|
||||
from numpy.typing import NDArray
|
||||
|
|
@ -21,7 +21,7 @@ def rotation_matrix_2d(theta: float) -> NDArray[numpy.float64]:
|
|||
[numpy.sin(theta), +numpy.cos(theta)]])
|
||||
|
||||
|
||||
def normalize_mirror(mirrored: Sequence[bool]) -> Tuple[bool, float]:
|
||||
def normalize_mirror(mirrored: Sequence[bool]) -> tuple[bool, float]:
|
||||
"""
|
||||
Converts 0-2 mirror operations `(mirror_across_x_axis, mirror_across_y_axis)`
|
||||
into 0-1 mirror operations and a rotation
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
"""
|
||||
Type definitions
|
||||
"""
|
||||
from typing import Union, Tuple, Dict, List, Protocol
|
||||
from typing import Protocol
|
||||
|
||||
|
||||
layer_t = Union[int, Tuple[int, int], str]
|
||||
annotations_t = Dict[str, List[Union[int, float, str]]]
|
||||
layer_t = int | tuple[int, int] | str
|
||||
annotations_t = dict[str, list[int | float | str]]
|
||||
|
||||
|
||||
class SupportsBool(Protocol):
|
||||
|
|
|
|||
|
|
@ -113,5 +113,3 @@ def poly_contains_points(
|
|||
inside = nontrivial.copy()
|
||||
inside[nontrivial] = nontrivial_inside
|
||||
return inside
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue