Skip to content

Add rudimentary Pillow stubs #5594

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

Merged
merged 4 commits into from
Jun 9, 2021
Merged

Add rudimentary Pillow stubs #5594

merged 4 commits into from
Jun 9, 2021

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Jun 9, 2021

No description provided.

@Akuli
Copy link
Collaborator

Akuli commented Jun 9, 2021

>>> from PIL import ImageTk
>>> ImageTk
<module 'PIL.ImageTk' from '/tmp/e/lib/python3.8/site-packages/PIL/ImageTk.py'>

But the stub doesn't contain ImageTk.py. Are other submodules missing too? Is this intentional?

@srittau
Copy link
Collaborator Author

srittau commented Jun 9, 2021

Yes, it's very incomplete. (But it has the required __getattr__() in __init__()).

@Akuli
Copy link
Collaborator

Akuli commented Jun 9, 2021

So in a stub, having __getattr__ in foobar/__init__.py also affects code like from foobar.submodule import thingy, even though that's not how it works at runtime?

@srittau
Copy link
Collaborator Author

srittau commented Jun 9, 2021

I thought it does, but I could be wrong. I will add empty stubs if that's not the case.

@srittau
Copy link
Collaborator Author

srittau commented Jun 9, 2021

I just checked with mypy and the following passes with these stubs:

from PIL.X import Y

reveal_type(Y)  # Revealed type is "Any"

@overload
def getdraw(im: None = ..., hints: Container[Literal["nicest"]] | None = ...) -> tuple[None, Any]: ...
@overload
def getdraw(im: Image, hints: Container[Literal["nicest"]] | None = ...) -> tuple[Image, Any]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure tuple[Foo, Bar] is not affected by the mypy bug?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only tuple[X, ...] and tuple (as well as others) in type aliases.

@JelleZijlstra
Copy link
Member

Fixed the merge conflict by removing it from the pyright exclude list.

@Akuli Akuli merged commit 5d811e1 into python:master Jun 9, 2021
@srittau srittau deleted the pil branch June 9, 2021 14:38
@jakebailey
Copy link
Contributor

Wish I had seen this; I have stubbed out quite a bit of PIL on our stub staging repo: https://github.com/microsoft/python-type-stubs/tree/main/PIL

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.

4 participants