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

Add type hints for Image.open, Image.init, and Image.Image.save #7944

Merged
merged 3 commits into from
Apr 6, 2024

Conversation

nulano
Copy link
Contributor

@nulano nulano commented Apr 4, 2024

Fixes #7941

While the Image.open function is currently marked as returning an Image object, it does so by calling a factory function from OPEN, which is marked as returning an ImageFile:

Pillow/src/PIL/Image.py

Lines 222 to 228 in e8ab564

OPEN: dict[
str,
tuple[
Callable[[IO[bytes], str | bytes], ImageFile.ImageFile],
Callable[[bytes], bool] | None,
],
] = {}

The accept function usually returns a bool, but I found one case (webp) where it can return a str instead to be used as a warning.

@aclark4life
Copy link
Member

Hmmm, jinx #7943 ?

@nulano nulano changed the title Add type hints for Image.open and Image.init Add type hints for Image.open, Image.init, and Image.Image.save Apr 4, 2024
@radarhere radarhere merged commit 84a02c8 into python-pillow:main Apr 6, 2024
57 checks passed
@nulano nulano deleted the type-image-open branch April 6, 2024 22:51
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.

Image.filename is not an exposed property
4 participants