Skip to content

Conversation

@radarhere
Copy link
Member

@radarhere radarhere commented Dec 18, 2022

Resolves #6809

In registered_extensions(), if there are any EXTENSIONS present, then it doesn't call init().

Pillow/src/PIL/Image.py

Lines 3416 to 3423 in 7f6fe3c

def registered_extensions():
"""
Returns a dictionary containing all file extensions belonging
to registered plugins
"""
if not EXTENSION:
init()
return EXTENSION

This means that

from PIL import Image
print(Image.registered_extensions())

returns more extensions than

from PIL import Image
import PIL.PngImagePlugin
print(Image.registered_extensions())

does. This seems unexpected to the user.

The original logic came from #1968, which was merged in #2343.

This PR adjusts it to always call init(), to make sure that all plugins are initialised. This is not an expensive operation, as there is still a check for the _initialized value to see if it has already been done.

I've adjusted the test to remove the resetting of EXTENSION, which is no longer relevant to this function.

@hugovk hugovk merged commit f9c88c9 into python-pillow:main Dec 23, 2022
@radarhere radarhere deleted the registered_extensions branch December 23, 2022 20:11
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.

importing PIL.PngImagePlugin breaks Image.registered_extensions()

2 participants