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

Allow pathlib.Path in Image.open on Python 2.7 #2110

Merged
merged 1 commit into from Sep 20, 2016

Conversation

patricksnape
Copy link
Contributor

Changes proposed in this pull request:

  • Allow using pathlib.Path for Image.open on Python 2.7

Although the pathlib backport for Python 2.7 may be deprecated:
https://pypi.python.org/pypi/pathlib/
It is still used by many projects. Therefore, changing to a
Try/Except pattern for checking for pathlib is not any more
obtrusive that the current >= Python 3.4 check and allows users
to use the backport without issue.

@@ -2279,10 +2279,14 @@ def open(fp, mode="r"):
filename = ""
if isPath(fp):
filename = fp
elif sys.version_info >= (3, 4):
Copy link
Member

Choose a reason for hiding this comment

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

Before, the pathlib stuff was only run when isPath(fp) is False (and Python >= 3.4).

Now, it's always run, whether isPath(fp) is False or True.

Should the try/except be put in an else case, so it's only run when isPath(fp) is False?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To maintain consistency with the previous behaviour you are totally right. This is now done.

Although the pathlib backport for Python 2.7 may be deprecated:
https://pypi.python.org/pypi/pathlib/
It is still used by many projects. Therefore, changing to a
Try/Except pattern for checking for pathlib is not any more
obtrusive that the current >= Python 3.4 check and allows users
to use the backport without issue.
@patricksnape
Copy link
Contributor Author

@hugovk Thanks for the review - that update has been made (force pushed)

@hugovk hugovk merged commit bc354d1 into python-pillow:master Sep 20, 2016
@hugovk
Copy link
Member

hugovk commented Sep 20, 2016

Thanks!

@patricksnape patricksnape deleted the allow_pathlib_py2 branch September 20, 2016 14:58
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.

None yet

2 participants