Skip to content

Check ext is not empty during save#145

Merged
hugovk merged 1 commit intohugovk:lazyfrom
radarhere:lazy
Jan 25, 2026
Merged

Check ext is not empty during save#145
hugovk merged 1 commit intohugovk:lazyfrom
radarhere:lazy

Conversation

@radarhere
Copy link
Copy Markdown

Suggestion for python-pillow#9398

When opening, there's a check that ext isn't empty.

Pillow/src/PIL/Image.py

Lines 3635 to 3637 in 2b186fc

ext = os.path.splitext(filename)[1] if filename else ""
if not (ext and _import_plugin_for_extension(ext)):
preinit()

When saving, there's no reason why ext derived from the filename couldn't also be empty. I mean, saving a file without a file extension or a format will raise an error in the end, but as far as this part of the code is concerned, ext could be empty.

Pillow/src/PIL/Image.py

Lines 2639 to 2648 in 2b186fc

filename_ext = os.path.splitext(filename)[1].lower()
ext = (
filename_ext.decode()
if isinstance(filename_ext, bytes)
else filename_ext
)
# Try importing only the plugin for this extension first
if not _import_plugin_for_extension(ext):
preinit()

So perhaps it is a good idea to move the check if ext is empty inside _import_plugin_for_extension()?

On the other hand, it is very clearly an edge case, and this change makes no real difference to the end result, so I don't mind if the main PR is merged with or without this.

@hugovk hugovk merged commit d568c8d into hugovk:lazy Jan 25, 2026
54 checks passed
@hugovk
Copy link
Copy Markdown
Owner

hugovk commented Jan 25, 2026

Sure, let's include this.

@radarhere radarhere deleted the lazy branch January 25, 2026 19:20
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.

2 participants