Skip to content

Commit 96e60df

Browse files
committed
Make Move a Path segment
For better type annotations
1 parent 60dbedc commit 96e60df

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Changelog
55
6.4b2 (unreleased)
66
------------------
77

8-
- Nothing changed yet.
8+
- Make the Move class a Path Segment, for type annotation consistency.
99

1010

1111
6.4b1 (2025-02-27)

src/svg/path/path.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ def boundingbox(self) -> List[float]:
760760
return [x_min, y_min, x_max, y_max]
761761

762762

763-
class Move:
763+
class Move(PathSegment):
764764
"""Represents move commands. Does nothing, but is there to handle
765765
paths that consist of only move commands, which is valid, but pointless.
766766
"""
@@ -834,7 +834,7 @@ def boundingbox(self) -> List[float]:
834834

835835
if TYPE_CHECKING:
836836

837-
class PathType(MutableSequence[Union[PathSegment, Move]]):
837+
class PathType(MutableSequence[PathSegment]):
838838
pass
839839

840840
else:
@@ -846,19 +846,19 @@ class PathType(MutableSequence):
846846
class Path(PathType):
847847
"""A Path is a sequence of path segments"""
848848

849-
def __init__(self, *segments: Union[PathSegment, Move]) -> None:
849+
def __init__(self, *segments: PathSegment) -> None:
850850
self._segments = list(segments)
851851
self._length: Union[float, None] = None
852852
self._lengths: Union[List[float], None] = None
853853
# Fractional distance from starting point through the end of each segment.
854854
self._fractions: List[float] = []
855855

856856
# TODO: Missing handling for slices.
857-
def __getitem__(self, index: int) -> Union[PathSegment, Move]: # type: ignore[override]
857+
def __getitem__(self, index: int) -> PathSegment: # type: ignore[override]
858858
return self._segments[index]
859859

860860
# TODO: Missing handling for slices.
861-
def __setitem__(self, index: int, value: Union[PathSegment, Move]) -> None: # type: ignore[override]
861+
def __setitem__(self, index: int, value: PathSegment) -> None: # type: ignore[override]
862862
self._segments[index] = value
863863
self._length = None
864864

@@ -867,7 +867,7 @@ def __delitem__(self, index: int) -> None: # type: ignore[override]
867867
del self._segments[index]
868868
self._length = None
869869

870-
def insert(self, index: int, value: Union[PathSegment, Move]) -> None:
870+
def insert(self, index: int, value: PathSegment) -> None:
871871
self._segments.insert(index, value)
872872
self._length = None
873873

@@ -917,7 +917,7 @@ def _calc_lengths(self, error: float = ERROR, min_depth: int = MIN_DEPTH) -> Non
917917

918918
def _find_segment(
919919
self, pos: float, error: float = ERROR
920-
) -> Tuple[Union[PathSegment, Move], float]:
920+
) -> Tuple[PathSegment, float]:
921921
# Shortcuts
922922
if pos == 0.0:
923923
return self._segments[0], pos

0 commit comments

Comments
 (0)