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

Added ImageType as alias for Image.Image #7639

Closed
wants to merge 6 commits into from

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Dec 26, 2023

Helps #2625.

Resolves #6676. Also suggested in #7635 (review)

When using the Image class as a type hint, you must currently use from PIL import Image; Image.Image.

This PR allows for from PIL import ImageType; ImageType.

hugovk
hugovk previously approved these changes Dec 26, 2023
src/PIL/__init__.py Show resolved Hide resolved
@nulano
Copy link
Contributor

nulano commented Dec 26, 2023

I wasn't sure how this would affect the docs, but it looks good:

image

Should ImageType be documented somewhere? Not sure how it would be done, since I couldn't find a type alias directive in sphinx: https://www.sphinx-doc.org/en/master/usage/domains/python.html

@radarhere
Copy link
Member Author

Ok, I've added it to the docs - https://pillow--7639.org.readthedocs.build/en/7639/reference/Image.html

Screenshot 2023-12-27 at 10 03 33 am

docs/reference/Image.rst Outdated Show resolved Hide resolved
Co-authored-by: Ondrej Baranovič <nulano@nulano.eu>
@hugovk hugovk dismissed their stale review December 29, 2023 19:42

See below.

@hugovk
Copy link
Member

hugovk commented Dec 29, 2023

I know I suggested this in the first place, but after some thought, perhaps it's not so useful after all.

Image.Image vs ImageType is adding abstraction on top of something which isn't particularly complex in the first place, only save two chars, at the cost of another layer of indirection.

I can see aliases may be more useful for more complex things, such as tuples of ints for RGB etc, but I think we should pass on this one.

@radarhere radarhere closed this Dec 29, 2023
@radarhere radarhere deleted the imagetype branch December 29, 2023 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typing difficulty because Image is a module and also a class
3 participants