Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The _Ink for ImageDraw does not support alpha channel #5754

Closed
pietermarsman opened this issue Oct 11, 2021 · 2 comments
Closed

The _Ink for ImageDraw does not support alpha channel #5754

pietermarsman opened this issue Oct 11, 2021 · 2 comments

Comments

@pietermarsman
Copy link

pietermarsman commented Oct 11, 2021

The type annotation for _Ink in in ImageDraw.pyi should also include a tuple with 4 integers.

What did you do?

Write code for drawing a rectangle.

from PIL.Image import Image
from PIL.ImageDraw import ImageDraw

img = Image()
draw = ImageDraw(img)
draw.rectangle(((0, 0), (100, 100)), (0, 0, 0, 100))

And run pytype.

pytype filename.py

What did you expect to happen?

Pytype was fine with the color with an alpha channel.

What actually happened?

PyType is not fine.

Computing dependencies
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `.pytype'
[1/1] check scratch_17
FAILED: /home/pieter/projects/orbisk/annotation_db/.pytype/pyi/scratch_17.pyi 
/home/pieter/.local/share/virtualenvs/annotation_db-Tf8o4jwu/bin/python -m pytype.single --imports_info /home/pieter/projects/orbisk/annotation_db/.pytype/imports/scratch_17.imports --module-name scratch_17 -V 3.7 -o /home/pieter/projects/orbisk/annotation_db/.pytype/pyi/scratch_17.pyi --analyze-annotated --nofail --quick /home/pieter/.config/JetBrains/PyCharm2021.2/scratches/scratch_17.py
File "/home/pieter/.config/JetBrains/PyCharm2021.2/scratches/scratch_17.py", line 6, in <module>: Function ImageDraw.rectangle was called with the wrong arguments [wrong-arg-types]
         Expected: (self, xy, fill: Optional[Union[int, str, Tuple[int, int, int]]] = ..., ...)
  Actually passed: (self, xy, fill: Tuple[int, int, int, int])

For more details, see https://google.github.io/pytype/errors.html#wrong-arg-types
ninja: build stopped: subcommand failed.
Leaving directory '.pytype'

Probably the same results with mypy.

What are your OS, Python and Pillow versions?

Not relevant.

@radarhere
Copy link
Member

Hi. As discussed in #5707, we don't actually have any typing in Pillow.

I'm guessing (https://www.jetbrains.com/help/pycharm/type-hinting-in-product.html#typeshed) that you're using Typeshed, in which case you may want to talk to https://github.com/python/typeshed. See https://github.com/python/typeshed/blob/master/stubs/Pillow/PIL/ImageDraw.pyi for their current typing in ImageDraw.

@pietermarsman
Copy link
Author

Looks right!

Thanks! I'll create an issue over there.

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

No branches or pull requests

2 participants