Skip to content

Added support for pathlib Path objects to open and save - #1372

Merged
hugovk merged 3 commits into
python-pillow:masterfrom
radarhere:pathlib
Aug 5, 2015
Merged

Added support for pathlib Path objects to open and save#1372
hugovk merged 3 commits into
python-pillow:masterfrom
radarhere:pathlib

Conversation

@radarhere

Copy link
Copy Markdown
Member

Resolves #1368

@hugovk

hugovk commented Aug 5, 2015

Copy link
Copy Markdown
Member

Looks good. Do we need to update the docstring or main docs anywhere?

@radarhere

Copy link
Copy Markdown
Member Author

Thanks for asking the question. From what I can see, it's just the docstrings.

hugovk added a commit that referenced this pull request Aug 5, 2015
Added support for pathlib Path objects to open and save
@hugovk
hugovk merged commit 60cb3f7 into python-pillow:master Aug 5, 2015
@radarhere
radarhere deleted the pathlib branch August 5, 2015 13:42
@radarhere radarhere mentioned this pull request Aug 5, 2015
Comment thread PIL/Image.py
filename = fp.name
else:
filename = ""
elif sys.version_info >= (3, 4):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm literally a year late on this, but this breaks support for passing in file objects (with a name property) in Python 3.4 and up. Previously the file name would be pulled from fp.name (assuming it was a valid path), but now because this check is in here for Python 3.4, it no longer pulls the file name. As a result, you must set the format explicitly whenever you are saving files now, as the filename will always be an empty string after this point (because a file object is not a path), which means it can't introspect the extension.

This is broken in Pillow 3.0.0 up to the latest master, and isn't documented anywhere.

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.

3 participants