Various type-checking improvements

This commit is contained in:
Jan Petykiewicz 2025-10-26 18:45:09 -07:00
commit 0c04bf8ea3
13 changed files with 27 additions and 26 deletions

View file

@ -42,7 +42,7 @@ class Arc(Shape):
# radius properties
@property
def radii(self) -> Any: # mypy#3004 NDArray[numpy.float64]:
def radii(self) -> NDArray[numpy.float64]:
"""
Return the radii `[rx, ry]`
"""
@ -79,7 +79,7 @@ class Arc(Shape):
# arc start/stop angle properties
@property
def angles(self) -> Any: # mypy#3004 NDArray[numpy.float64]:
def angles(self) -> NDArray[numpy.float64]:
"""
Return the start and stop angles `[a_start, a_stop]`.
Angles are measured from x-axis after rotation
@ -412,15 +412,15 @@ class Arc(Shape):
start_angle -= pi
rotation += pi
angles = (start_angle, start_angle + delta_angle)
norm_angles = (start_angle, start_angle + delta_angle)
rotation %= 2 * pi
width = self.width
return ((type(self), radii, angles, width / norm_value),
return ((type(self), radii, norm_angles, width / norm_value),
(self.offset, scale / norm_value, rotation, False),
lambda: Arc(
radii=radii * norm_value,
angles=angles,
angles=norm_angles,
width=width * norm_value,
))

View file

@ -33,7 +33,7 @@ class Ellipse(Shape):
# radius properties
@property
def radii(self) -> Any: # mypy#3004 NDArray[numpy.float64]:
def radii(self) -> NDArray[numpy.float64]:
"""
Return the radii `[rx, ry]`
"""

View file

@ -87,7 +87,7 @@ class Path(Shape):
# cap_extensions property
@property
def cap_extensions(self) -> Any | None: # mypy#3004 NDArray[numpy.float64]]:
def cap_extensions(self) -> NDArray[numpy.float64] | None:
"""
Path end-cap extension
@ -113,7 +113,7 @@ class Path(Shape):
# vertices property
@property
def vertices(self) -> Any: # mypy#3004 NDArray[numpy.float64]]:
def vertices(self) -> NDArray[numpy.float64]:
"""
Vertices of the path (Nx2 ndarray: `[[x0, y0], [x1, y1], ...]`

View file

@ -37,14 +37,14 @@ class PolyCollection(Shape):
""" 1D NDArray specifying the starting offset for each polygon """
@property
def vertex_lists(self) -> Any: # mypy#3004 NDArray[numpy.float64]:
def vertex_lists(self) -> NDArray[numpy.float64]:
"""
Vertices of the polygons, ((N+M+...) x 2). Use with `vertex_offsets`.
"""
return self._vertex_lists
@property
def vertex_offsets(self) -> Any: # mypy#3004 NDArray[numpy.intp]:
def vertex_offsets(self) -> NDArray[numpy.intp]:
"""
Starting offset (in `vertex_lists`) for each polygon
"""

View file

@ -38,7 +38,7 @@ class Polygon(Shape):
# vertices property
@property
def vertices(self) -> Any: # mypy#3004 NDArray[numpy.float64]:
def vertices(self) -> NDArray[numpy.float64]:
"""
Vertices of the polygon (Nx2 ndarray: `[[x0, y0], [x1, y1], ...]`)

View file

@ -10,7 +10,7 @@ from . import Shape, Polygon, normalized_shape_tuple
from ..error import PatternError
from ..repetition import Repetition
from ..traits import RotatableImpl
from ..utils import is_scalar, get_bit, annotations_t, annotations_lt, annotations_eq, rep2key
from ..utils import is_scalar, get_bit, annotations_t, annotations_lt, annotations_eq, rep2key, SupportsBool
# Loaded on use:
# from freetype import Face
@ -55,11 +55,11 @@ class Text(RotatableImpl, Shape):
self._height = val
@property
def mirrored(self) -> bool: # mypy#3004, should be bool
def mirrored(self) -> bool:
return self._mirrored
@mirrored.setter
def mirrored(self, val: bool) -> None:
def mirrored(self, val: SupportsBool) -> None:
self._mirrored = bool(val)
def __init__(
@ -201,7 +201,7 @@ def get_char_as_polygons(
font_path: str,
char: str,
resolution: float = 48 * 64,
) -> tuple[list[list[list[float]]], float]:
) -> tuple[list[NDArray[numpy.float64]], float]:
from freetype import Face # type: ignore
from matplotlib.path import Path # type: ignore
@ -276,11 +276,12 @@ def get_char_as_polygons(
advance = slot.advance.x / resolution
polygons: list[NDArray[numpy.float64]]
if len(all_verts) == 0:
polygons = []
else:
path = Path(all_verts, all_codes)
path.should_simplify = False
polygons = path.to_polygons()
polygons = [numpy.asarray(poly) for poly in path.to_polygons()]
return polygons, advance