Do not allow coords to be sequence of lists

This commit is contained in:
Andrew Murray 2025-03-05 13:50:13 +11:00
parent c7ed097dd1
commit 177629ca5e
3 changed files with 7 additions and 11 deletions

View File

@ -802,14 +802,10 @@ def test_rectangle_translucent_outline(bbox: Coords) -> None:
@pytest.mark.parametrize(
"xy",
[(10, 20, 190, 180), ([10, 20], [190, 180]), ((10, 20), (190, 180))],
[(10, 20, 190, 180), ((10, 20), (190, 180))],
)
def test_rounded_rectangle(
xy: (
tuple[int, int, int, int]
| tuple[list[int]]
| tuple[tuple[int, int], tuple[int, int]]
),
xy: tuple[int, int, int, int] | tuple[tuple[int, int], tuple[int, int]],
) -> None:
# Arrange
im = Image.new("RGB", (200, 200))

View File

@ -244,12 +244,12 @@ class ImageDraw:
if ink is not None:
self.draw.draw_lines(xy, ink, width)
if joint == "curve" and width > 4:
points: Sequence[Sequence[float]]
if isinstance(xy[0], (list, tuple)):
points = cast(Sequence[Sequence[float]], xy)
points: Sequence[tuple[float, ...]]
if isinstance(xy[0], tuple):
points = cast(Sequence[tuple[float, ...]], xy)
else:
points = [
cast(Sequence[float], tuple(xy[i : i + 2]))
tuple(cast(Sequence[float], xy)[i : i + 2])
for i in range(0, len(xy), 2)
]
for i in range(1, len(points) - 1):

View File

@ -37,7 +37,7 @@ else:
return bool
Coords = Union[Sequence[float], Sequence[Sequence[float]]]
Coords = Union[Sequence[float], Sequence[tuple[float, ...]]]
_T_co = TypeVar("_T_co", covariant=True)