You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Coords allows Sequence[Sequence], so it should support both tuple[tuple] and list[list] but currently it doesn't seem to be the case with ImageDraw.line - it fails with list[list] at runtime though there are no typing errors.
See example below.
fromPILimportImage, ImageDrawimportnumpyasnpimg_size= (200, 200)
scale=1.0img=Image.new("RGB", img_size, "white")
draw=ImageDraw.Draw(img)
verts=np.array(
[
[[22.0, 105.0], [114.0, 105.0]],
[[22.0, 105.0], [22.0, 23.0]],
[[114.0, 105.0], [114.0, 113.0]],
[[114.0, 113.0], [14.0, 113.0]],
[[14.0, 113.0], [14.0, 15.0]],
[[14.0, 15.0], [114.0, 15.0]],
[[114.0, 15.0], [114.0, 23.0]],
[[114.0, 23.0], [22.0, 23.0]],
]
)
forverts_inverts:
lst: list[list[float]]
lst=verts_.tolist()
# No typing errors but fails at runtime.# Traceback (most recent call last):# File "second_test.py", line 28, in <module># draw.line(verts_.tolist(), fill="black", width=2)# File "\Lib\site-packages\PIL\ImageDraw.py", line 249, in line# self.draw.draw_lines(xy, ink, width)# ValueError: incorrect coordinate type# draw.line(lst, fill="black", width=2)# Works fine, list of tuples also work fine too.tple=tuple(tuple(i) foriinverts_)
draw.line(tple, fill="black", width=2)
# Show the imageimg.show()
The text was updated successfully, but these errors were encountered:
Hi. Prior to adding type hints, the idea of a sequence of lists for co-ordinates was discussed in #3738, and declined. However, I suppose the fact that we have existing type hints that suggest this is a new argument.
I've created #8800, to allow a sequence of lists, and #8802 to change the type hint instead to not allow it. We'll see what happens.
ImageDraw.line
is currently usingCoords
forxy
argument.Pillow/src/PIL/ImageDraw.py
Line 237 in c7ed097
Pillow/src/PIL/_typing.py
Line 40 in c7ed097
Coords
allowsSequence[Sequence]
, so it should support bothtuple[tuple]
andlist[list]
but currently it doesn't seem to be the case withImageDraw.line
- it fails withlist[list]
at runtime though there are no typing errors.See example below.
The text was updated successfully, but these errors were encountered: