-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix image fmt detection for Path input. #10754
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
Conversation
ce2b1fd
to
19d4e8c
Compare
lib/matplotlib/tests/test_figure.py
Outdated
@@ -1,6 +1,4 @@ | |||
from __future__ import absolute_import, division, print_function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're backporting, you don't want to remove this.
19d4e8c
to
8605b35
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@@ -2130,6 +2130,8 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None, | |||
|
|||
if format is None: | |||
# get format from filename, or from backend's default filetype | |||
if isinstance(filename, getattr(os, "PathLike", ())): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I correct, that this will only fix the format detection for Python 3.6+? Since this will probably go into 2.2.x. it should also hande pre-python3.6 Path objects, i.e. check for Path
instance and use filename = str(filename)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also PEP-519 states
Libraries wishing to support path objects and a version of Python prior to Python 3.6 and the existence of
os.fspath()
can use the idiom ofpath.__fspath__() if hasattr(path, "__fspath__") else path
.
But that's more a matter of taste.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original PR explicitly only supported 3.6+ (see whatsnew note in https://github.com/matplotlib/matplotlib/pull/10231/files). I have no intent to reimplement the pathlike API on <3.6.
So I'll leave things as they are.
Backport PR #10754 on branch v2.2.x
PR Summary
Fixes #10753. Should probably go to 2.2.1 as the feature is basically unusable without the fix.
PR Checklist