-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MNT: prefer Figure.clear() as canonical over Figure.clf() #22735
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
6b2777b
to
7341ff7
Compare
7341ff7
to
f37add1
Compare
Should we then do that for |
cla is a heaver lift (there are a lot more of them) and apparently have even started to deprecate matplotlib/lib/matplotlib/projections/polar.py Lines 380 to 382 in da9533d
|
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.
Yeah, I think "clear" is clearer than "clf" (sorry) and should be preferred.
I'm confused by the milestoning here. I think we can mark as 3.6? |
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.
Anybody can merge after CI pass.
4e677b1
to
cef64ad
Compare
lib/matplotlib/figure.py
Outdated
# a literal alias that correctly behaves for sub-classes (without resorting | ||
# to __subclass_init__ or other meta-programming tools. | ||
@property | ||
def clf(self): |
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.
Just checking if the docstring gets copied here too?
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.
It does not :(
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.
well, help(fig.clf)
works, but ? fig.clf
is too smart and gives the property docstring.
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 we care about the docstring, this should be good enough.
def clf(self):
"""Clear the figure. Synonym for ``clear()``."""
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.
Let's not overengineer this. Plus, this still doesn't prevent someone from accidentally overriding clf, and also breaks using unbound methods (Figure.clear(fig)
-- probably exceptionally rare, but there's no good reason to break it...).
cef64ad
to
05c463c
Compare
lib/matplotlib/tests/test_figure.py
Outdated
@@ -790,6 +790,15 @@ def test_figure_clear(): | |||
assert fig.axes == [] | |||
|
|||
|
|||
def test_clf_is_clear(): |
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.
Can we add a test for the peplos version as well, just in case?
7aea0fd
to
1cbc34a
Compare
ok, I gave up on all of the fancy attempts at meta-programming / proxy magic as too clever by half. I put an honest wrapper on the base class, added a test that they behave the same and that we do not defined |
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.
I'm ok with this approach, but let's make it clear in the docstring that clf()
is discouraged.
Can merge after the docstring update.
5caa225
to
3587b8b
Compare
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove the If these instructions are inaccurate, feel free to suggest an improvement. |
@tacaswell do you want to backport to 3.5.2? I think it's ok to leave this to 3.6.0. |
There is a latent bug from #22138 , I'll see what the backport looks like. |
… over Figure.clf() Merge pull request matplotlib#22735 from tacaswell/mnt_prefer_clear MNT: prefer Figure.clear() as canonical over Figure.clf() (cherry picked from commit 6fedb48)
This is backported as part of #22737 |
… over Figure.clf() Merge pull request matplotlib#22735 from tacaswell/mnt_prefer_clear MNT: prefer Figure.clear() as canonical over Figure.clf() (cherry picked from commit 6fedb48)
PR Summary
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Follow on to #22138 adjusting the canonical name.