Skip to content

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
@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