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

Undocumented breaking change in Pillow 11.0.0 for im attribute #8581

Closed
OvervCW opened this issue Dec 3, 2024 · 7 comments
Closed

Undocumented breaking change in Pillow 11.0.0 for im attribute #8581

OvervCW opened this issue Dec 3, 2024 · 7 comments

Comments

@OvervCW
Copy link

OvervCW commented Dec 3, 2024

What did you do?

image = Image.open(path)

if not image.im:
    print("image still needs to be loaded")

What did you expect to happen?

Originally the im attribute would simply be None if the image was not loaded yet, which you could access to check this.

What actually happened?

Now accessing the im attribute when the image has not been loaded yet results in an assertion error.

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 24.04.1 LTS
  • Python: 3.9.10
  • Pillow: 11.0.0
--------------------------------------------------------------------
Pillow 11.0.0
Python 3.9.10 (main, May 18 2022, 12:54:46)
       [GCC 11.2.0]
--------------------------------------------------------------------
Python executable is /home/alexander/.cache/pypoetry/virtualenvs/blicker-qkSPJuWY-py3.9/bin/python
Environment Python files loaded from /home/alexander/.cache/pypoetry/virtualenvs/blicker-qkSPJuWY-py3.9
System Python files loaded from /home/alexander/.pyenv/versions/3.9.10
--------------------------------------------------------------------
Python Pillow modules loaded from /home/alexander/.cache/pypoetry/virtualenvs/blicker-qkSPJuWY-py3.9/lib/python3.9/site-packages/PIL
Binary Pillow modules loaded from /home/alexander/.cache/pypoetry/virtualenvs/blicker-qkSPJuWY-py3.9/lib/python3.9/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 11.0.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.4.0
--- JPEG support ok, compiled for libjpeg-turbo 3.0.4
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.3
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.13, harfbuzz 10.0.1
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------```
@radarhere
Copy link
Member

radarhere commented Dec 3, 2024

Hi. This change was made in #8279. While you could use if not image._im: instead, I think part of the problem is that this attribute wasn't a documented one, and so we felt more comfortable changing it.

Might I suggest replacing if not image.im: with if image.tile:? This would be better, as it is using a documented attribute - https://pillow.readthedocs.io/en/stable/reference/ImageFile.html#PIL.ImageFile.ImageFile.tile

@OvervCW
Copy link
Author

OvervCW commented Dec 3, 2024

@radarhere How would I use tile to accomplish the same kind of check? It seems to not be None even if _im is None.

@radarhere
Copy link
Member

radarhere commented Dec 3, 2024

tile should be a non-empty list when the image needs to be loaded, and an empty list when it is loaded.

@radarhere
Copy link
Member

I'm also curious to know why you wish to check if an image has been loaded or not in the first place?

@OvervCW
Copy link
Author

OvervCW commented Dec 4, 2024

Admittedly a bit of a niche scenario, but in our code it's to know if opening the image should be retried if it previously failed to be loaded due to file corruption.

@radarhere
Copy link
Member

Has my suggestion solved your problem?

@OvervCW
Copy link
Author

OvervCW commented Dec 5, 2024

@radarhere Yes, thank you.

@OvervCW OvervCW closed this as completed Dec 5, 2024
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