22
33import contextlib
44import os .path
5- from typing import Sequence
65
76import pytest
87
98from PIL import Image , ImageColor , ImageDraw , ImageFont , features
9+ from PIL ._typing import CoordList
1010
1111from .helper import (
1212 assert_image_equal ,
@@ -75,7 +75,7 @@ def test_mode_mismatch() -> None:
7575
7676@pytest .mark .parametrize ("bbox" , BBOX )
7777@pytest .mark .parametrize ("start, end" , ((0 , 180 ), (0.5 , 180.4 )))
78- def test_arc (bbox : Sequence [ int | Sequence [ int ]] , start : float , end : float ) -> None :
78+ def test_arc (bbox : CoordList , start : float , end : float ) -> None :
7979 # Arrange
8080 im = Image .new ("RGB" , (W , H ))
8181 draw = ImageDraw .Draw (im )
@@ -88,7 +88,7 @@ def test_arc(bbox: Sequence[int | Sequence[int]], start: float, end: float) -> N
8888
8989
9090@pytest .mark .parametrize ("bbox" , BBOX )
91- def test_arc_end_le_start (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
91+ def test_arc_end_le_start (bbox : CoordList ) -> None :
9292 # Arrange
9393 im = Image .new ("RGB" , (W , H ))
9494 draw = ImageDraw .Draw (im )
@@ -103,7 +103,7 @@ def test_arc_end_le_start(bbox: Sequence[int | Sequence[int]]) -> None:
103103
104104
105105@pytest .mark .parametrize ("bbox" , BBOX )
106- def test_arc_no_loops (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
106+ def test_arc_no_loops (bbox : CoordList ) -> None :
107107 # No need to go in loops
108108 # Arrange
109109 im = Image .new ("RGB" , (W , H ))
@@ -119,7 +119,7 @@ def test_arc_no_loops(bbox: Sequence[int | Sequence[int]]) -> None:
119119
120120
121121@pytest .mark .parametrize ("bbox" , BBOX )
122- def test_arc_width (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
122+ def test_arc_width (bbox : CoordList ) -> None :
123123 # Arrange
124124 im = Image .new ("RGB" , (W , H ))
125125 draw = ImageDraw .Draw (im )
@@ -132,7 +132,7 @@ def test_arc_width(bbox: Sequence[int | Sequence[int]]) -> None:
132132
133133
134134@pytest .mark .parametrize ("bbox" , BBOX )
135- def test_arc_width_pieslice_large (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
135+ def test_arc_width_pieslice_large (bbox : CoordList ) -> None :
136136 # Tests an arc with a large enough width that it is a pieslice
137137 # Arrange
138138 im = Image .new ("RGB" , (W , H ))
@@ -146,7 +146,7 @@ def test_arc_width_pieslice_large(bbox: Sequence[int | Sequence[int]]) -> None:
146146
147147
148148@pytest .mark .parametrize ("bbox" , BBOX )
149- def test_arc_width_fill (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
149+ def test_arc_width_fill (bbox : CoordList ) -> None :
150150 # Arrange
151151 im = Image .new ("RGB" , (W , H ))
152152 draw = ImageDraw .Draw (im )
@@ -159,7 +159,7 @@ def test_arc_width_fill(bbox: Sequence[int | Sequence[int]]) -> None:
159159
160160
161161@pytest .mark .parametrize ("bbox" , BBOX )
162- def test_arc_width_non_whole_angle (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
162+ def test_arc_width_non_whole_angle (bbox : CoordList ) -> None :
163163 # Arrange
164164 im = Image .new ("RGB" , (W , H ))
165165 draw = ImageDraw .Draw (im )
@@ -201,7 +201,7 @@ def test_bitmap() -> None:
201201
202202@pytest .mark .parametrize ("mode" , ("RGB" , "L" ))
203203@pytest .mark .parametrize ("bbox" , BBOX )
204- def test_chord (mode : str , bbox : Sequence [ int | Sequence [ int ]] ) -> None :
204+ def test_chord (mode : str , bbox : CoordList ) -> None :
205205 # Arrange
206206 im = Image .new (mode , (W , H ))
207207 draw = ImageDraw .Draw (im )
@@ -215,7 +215,7 @@ def test_chord(mode: str, bbox: Sequence[int | Sequence[int]]) -> None:
215215
216216
217217@pytest .mark .parametrize ("bbox" , BBOX )
218- def test_chord_width (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
218+ def test_chord_width (bbox : CoordList ) -> None :
219219 # Arrange
220220 im = Image .new ("RGB" , (W , H ))
221221 draw = ImageDraw .Draw (im )
@@ -228,7 +228,7 @@ def test_chord_width(bbox: Sequence[int | Sequence[int]]) -> None:
228228
229229
230230@pytest .mark .parametrize ("bbox" , BBOX )
231- def test_chord_width_fill (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
231+ def test_chord_width_fill (bbox : CoordList ) -> None :
232232 # Arrange
233233 im = Image .new ("RGB" , (W , H ))
234234 draw = ImageDraw .Draw (im )
@@ -241,7 +241,7 @@ def test_chord_width_fill(bbox: Sequence[int | Sequence[int]]) -> None:
241241
242242
243243@pytest .mark .parametrize ("bbox" , BBOX )
244- def test_chord_zero_width (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
244+ def test_chord_zero_width (bbox : CoordList ) -> None :
245245 # Arrange
246246 im = Image .new ("RGB" , (W , H ))
247247 draw = ImageDraw .Draw (im )
@@ -267,7 +267,7 @@ def test_chord_too_fat() -> None:
267267
268268@pytest .mark .parametrize ("mode" , ("RGB" , "L" ))
269269@pytest .mark .parametrize ("bbox" , BBOX )
270- def test_ellipse (mode : str , bbox : Sequence [ int | Sequence [ int ]] ) -> None :
270+ def test_ellipse (mode : str , bbox : CoordList ) -> None :
271271 # Arrange
272272 im = Image .new (mode , (W , H ))
273273 draw = ImageDraw .Draw (im )
@@ -281,7 +281,7 @@ def test_ellipse(mode: str, bbox: Sequence[int | Sequence[int]]) -> None:
281281
282282
283283@pytest .mark .parametrize ("bbox" , BBOX )
284- def test_ellipse_translucent (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
284+ def test_ellipse_translucent (bbox : CoordList ) -> None :
285285 # Arrange
286286 im = Image .new ("RGB" , (W , H ))
287287 draw = ImageDraw .Draw (im , "RGBA" )
@@ -318,7 +318,7 @@ def test_ellipse_symmetric() -> None:
318318
319319
320320@pytest .mark .parametrize ("bbox" , BBOX )
321- def test_ellipse_width (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
321+ def test_ellipse_width (bbox : CoordList ) -> None :
322322 # Arrange
323323 im = Image .new ("RGB" , (W , H ))
324324 draw = ImageDraw .Draw (im )
@@ -343,7 +343,7 @@ def test_ellipse_width_large() -> None:
343343
344344
345345@pytest .mark .parametrize ("bbox" , BBOX )
346- def test_ellipse_width_fill (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
346+ def test_ellipse_width_fill (bbox : CoordList ) -> None :
347347 # Arrange
348348 im = Image .new ("RGB" , (W , H ))
349349 draw = ImageDraw .Draw (im )
@@ -356,7 +356,7 @@ def test_ellipse_width_fill(bbox: Sequence[int | Sequence[int]]) -> None:
356356
357357
358358@pytest .mark .parametrize ("bbox" , BBOX )
359- def test_ellipse_zero_width (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
359+ def test_ellipse_zero_width (bbox : CoordList ) -> None :
360360 # Arrange
361361 im = Image .new ("RGB" , (W , H ))
362362 draw = ImageDraw .Draw (im )
@@ -410,12 +410,7 @@ def test_ellipse_various_sizes_filled() -> None:
410410
411411
412412@pytest .mark .parametrize ("points" , POINTS )
413- def test_line (
414- points : tuple [tuple [int , int ], ...]
415- | list [tuple [int , int ]]
416- | tuple [int , ...]
417- | list [int ]
418- ) -> None :
413+ def test_line (points : CoordList ) -> None :
419414 # Arrange
420415 im = Image .new ("RGB" , (W , H ))
421416 draw = ImageDraw .Draw (im )
@@ -488,9 +483,7 @@ def test_transform() -> None:
488483
489484@pytest .mark .parametrize ("bbox" , BBOX )
490485@pytest .mark .parametrize ("start, end" , ((- 92 , 46 ), (- 92.2 , 46.2 )))
491- def test_pieslice (
492- bbox : Sequence [int | Sequence [int ]], start : float , end : float
493- ) -> None :
486+ def test_pieslice (bbox : CoordList , start : float , end : float ) -> None :
494487 # Arrange
495488 im = Image .new ("RGB" , (W , H ))
496489 draw = ImageDraw .Draw (im )
@@ -503,7 +496,7 @@ def test_pieslice(
503496
504497
505498@pytest .mark .parametrize ("bbox" , BBOX )
506- def test_pieslice_width (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
499+ def test_pieslice_width (bbox : CoordList ) -> None :
507500 # Arrange
508501 im = Image .new ("RGB" , (W , H ))
509502 draw = ImageDraw .Draw (im )
@@ -516,7 +509,7 @@ def test_pieslice_width(bbox: Sequence[int | Sequence[int]]) -> None:
516509
517510
518511@pytest .mark .parametrize ("bbox" , BBOX )
519- def test_pieslice_width_fill (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
512+ def test_pieslice_width_fill (bbox : CoordList ) -> None :
520513 # Arrange
521514 im = Image .new ("RGB" , (W , H ))
522515 draw = ImageDraw .Draw (im )
@@ -530,7 +523,7 @@ def test_pieslice_width_fill(bbox: Sequence[int | Sequence[int]]) -> None:
530523
531524
532525@pytest .mark .parametrize ("bbox" , BBOX )
533- def test_pieslice_zero_width (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
526+ def test_pieslice_zero_width (bbox : CoordList ) -> None :
534527 # Arrange
535528 im = Image .new ("RGB" , (W , H ))
536529 draw = ImageDraw .Draw (im )
@@ -585,12 +578,7 @@ def test_pieslice_no_spikes() -> None:
585578
586579
587580@pytest .mark .parametrize ("points" , POINTS )
588- def test_point (
589- points : tuple [tuple [int , int ], ...]
590- | list [tuple [int , int ]]
591- | tuple [int , ...]
592- | list [int ]
593- ) -> None :
581+ def test_point (points : CoordList ) -> None :
594582 # Arrange
595583 im = Image .new ("RGB" , (W , H ))
596584 draw = ImageDraw .Draw (im )
@@ -615,12 +603,7 @@ def test_point_I16() -> None:
615603
616604
617605@pytest .mark .parametrize ("points" , POINTS )
618- def test_polygon (
619- points : tuple [tuple [int , int ], ...]
620- | list [tuple [int , int ]]
621- | tuple [int , ...]
622- | list [int ]
623- ) -> None :
606+ def test_polygon (points : CoordList ) -> None :
624607 # Arrange
625608 im = Image .new ("RGB" , (W , H ))
626609 draw = ImageDraw .Draw (im )
@@ -693,7 +676,7 @@ def test_polygon_translucent() -> None:
693676
694677
695678@pytest .mark .parametrize ("bbox" , BBOX )
696- def test_rectangle (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
679+ def test_rectangle (bbox : CoordList ) -> None :
697680 # Arrange
698681 im = Image .new ("RGB" , (W , H ))
699682 draw = ImageDraw .Draw (im )
@@ -720,7 +703,7 @@ def test_big_rectangle() -> None:
720703
721704
722705@pytest .mark .parametrize ("bbox" , BBOX )
723- def test_rectangle_width (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
706+ def test_rectangle_width (bbox : CoordList ) -> None :
724707 # Arrange
725708 im = Image .new ("RGB" , (W , H ))
726709 draw = ImageDraw .Draw (im )
@@ -734,7 +717,7 @@ def test_rectangle_width(bbox: Sequence[int | Sequence[int]]) -> None:
734717
735718
736719@pytest .mark .parametrize ("bbox" , BBOX )
737- def test_rectangle_width_fill (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
720+ def test_rectangle_width_fill (bbox : CoordList ) -> None :
738721 # Arrange
739722 im = Image .new ("RGB" , (W , H ))
740723 draw = ImageDraw .Draw (im )
@@ -748,7 +731,7 @@ def test_rectangle_width_fill(bbox: Sequence[int | Sequence[int]]) -> None:
748731
749732
750733@pytest .mark .parametrize ("bbox" , BBOX )
751- def test_rectangle_zero_width (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
734+ def test_rectangle_zero_width (bbox : CoordList ) -> None :
752735 # Arrange
753736 im = Image .new ("RGB" , (W , H ))
754737 draw = ImageDraw .Draw (im )
@@ -761,7 +744,7 @@ def test_rectangle_zero_width(bbox: Sequence[int | Sequence[int]]) -> None:
761744
762745
763746@pytest .mark .parametrize ("bbox" , BBOX )
764- def test_rectangle_I16 (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
747+ def test_rectangle_I16 (bbox : CoordList ) -> None :
765748 # Arrange
766749 im = Image .new ("I;16" , (W , H ))
767750 draw = ImageDraw .Draw (im )
@@ -774,7 +757,7 @@ def test_rectangle_I16(bbox: Sequence[int | Sequence[int]]) -> None:
774757
775758
776759@pytest .mark .parametrize ("bbox" , BBOX )
777- def test_rectangle_translucent_outline (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
760+ def test_rectangle_translucent_outline (bbox : CoordList ) -> None :
778761 # Arrange
779762 im = Image .new ("RGB" , (W , H ))
780763 draw = ImageDraw .Draw (im , "RGBA" )
@@ -866,7 +849,7 @@ def test_rounded_rectangle_non_integer_radius(
866849
867850
868851@pytest .mark .parametrize ("bbox" , BBOX )
869- def test_rounded_rectangle_zero_radius (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
852+ def test_rounded_rectangle_zero_radius (bbox : CoordList ) -> None :
870853 # Arrange
871854 im = Image .new ("RGB" , (W , H ))
872855 draw = ImageDraw .Draw (im )
@@ -907,7 +890,7 @@ def test_rounded_rectangle_translucent(
907890
908891
909892@pytest .mark .parametrize ("bbox" , BBOX )
910- def test_floodfill (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
893+ def test_floodfill (bbox : CoordList ) -> None :
911894 red = ImageColor .getrgb ("red" )
912895
913896 for mode , value in [("L" , 1 ), ("RGBA" , (255 , 0 , 0 , 0 )), ("RGB" , red )]:
@@ -940,7 +923,7 @@ def test_floodfill(bbox: Sequence[int | Sequence[int]]) -> None:
940923
941924
942925@pytest .mark .parametrize ("bbox" , BBOX )
943- def test_floodfill_border (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
926+ def test_floodfill_border (bbox : CoordList ) -> None :
944927 # floodfill() is experimental
945928
946929 # Arrange
@@ -962,7 +945,7 @@ def test_floodfill_border(bbox: Sequence[int | Sequence[int]]) -> None:
962945
963946
964947@pytest .mark .parametrize ("bbox" , BBOX )
965- def test_floodfill_thresh (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
948+ def test_floodfill_thresh (bbox : CoordList ) -> None :
966949 # floodfill() is experimental
967950
968951 # Arrange
@@ -1419,7 +1402,7 @@ def test_default_font_size() -> None:
14191402
14201403
14211404@pytest .mark .parametrize ("bbox" , BBOX )
1422- def test_same_color_outline (bbox : Sequence [ int | Sequence [ int ]] ) -> None :
1405+ def test_same_color_outline (bbox : CoordList ) -> None :
14231406 # Prepare shape
14241407 x0 , y0 = 5 , 5
14251408 x1 , y1 = 5 , 50
0 commit comments