Skip to content

Conversation

@radarhere
Copy link
Member

Resolves #5939

When drawing a rectangle,

from PIL import Image, ImageDraw
im = Image.new("RGB", (1, 1))
draw = ImageDraw.Draw(im)
draw.rectangle((0, 0, 1, 1))

if the wrong coordinate type is used,

from PIL import Image, ImageDraw
im = Image.new("RGB", (1, 1))
draw = ImageDraw.Draw(im)
draw.rectangle(('0', '0', '1', '1'))

the error given is

Traceback (most recent call last):
  File "demo.py", line 4, in <module>
    draw.rectangle(('0', '0', '1', '1'))
  File "PIL/ImageDraw.py", line 259, in rectangle
    self.draw.draw_rectangle(xy, ink, 0, width)
SystemError: new style getargs format but argument is not a tuple

The issue points out that this is not terribly clear. Instead, this PR changes it to

Traceback (most recent call last):
  File "demo.py", line 4, in <module>
    draw.rectangle(('0', '0', '1', '1'))
  File "PIL/ImageDraw.py", line 279, in rectangle
ValueError: incorrect coordinate type

I also reduce some duplicate code at the same time.

@hugovk hugovk merged commit eff6c34 into python-pillow:main Jan 8, 2022
@radarhere radarhere deleted the error branch January 8, 2022 21:55
@radarhere radarhere changed the title Added specific error if ImagePath coordinate type is incorrect Added specific error if path coordinate type is incorrect Feb 10, 2022
radarhere added a commit to radarhere/Pillow that referenced this pull request Feb 10, 2022
radarhere added a commit to radarhere/Pillow that referenced this pull request Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading error message when passing tuple of incorrect data type to ImageDraw methods

2 participants