8000 MNT: prefer Figure.clear() as canonical over Figure.clf() by tacaswell · Pull Request #22735 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 3 commits into from
Apr 5, 2022

Conversation

tacaswell
Copy link
Member

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Follow on to #22138 adjusting the canonical name.

@tacaswell tacaswell added this to the v3.7.0 milestone Mar 30, 2022
@tacaswell tacaswell force-pushed the mnt_prefer_clear branch 2 times, most recently from 6b2777b to 7341ff7 Compare March 30, 2022 21:08
@tacaswell tacaswell changed the title MNT: prefer "clear" as cannonical over clf MNT: prefer "clear" as canonical over clf Mar 30, 2022
@QuLogic
Copy link
Member
QuLogic commented Mar 30, 2022

Should we then do that for cla as well?

@tacaswell
Copy link
Member Author

cla is a heaver lift (there are a lot more of them) and apparently have even started to deprecate cla

@_api.deprecated("3.4", alternative="ThetaAxis.clear()")
def cla(self):
self.clear()

Copy link
Member
@jklymak jklymak left a 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.

@jklymak
Copy link
Member
jklymak commented Mar 31, 2022

I'm confused by the milestoning here. I think we can mark as 3.6?

Copy link
Member
@timhoffm timhoffm left a 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.

# a literal alias that correctly behaves for sub-classes (without resorting
# to __subclass_init__ or other meta-programming tools.
@property
def clf(self):
Copy link
Member
@QuLogic QuLogic Mar 31, 2022

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does not :(

Copy link
Member Author

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.

Copy link
Member

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()``."""

Copy link
Contributor

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...).

@@ -790,6 +790,15 @@ def test_figure_clear():
assert fig.axes == []


def test_clf_is_clear():
Copy link
Member

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?

@tacaswell
Copy link
Member Author

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 clf on any of our sub-classes.

Copy link
Member
@timhoffm timhoffm left a 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.

Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@timhoffm timhoffm changed the title MNT: prefer "clear" as canonical over clf MNT: prefer Figure.clear() as canonical over Figure.clf() Apr 5, 2022
@timhoffm timhoffm merged commit 6fedb48 into matplotlib:main Apr 5, 2022
@lumberbot-app
Copy link
lumberbot-app bot commented Apr 5, 2022

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.5.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 6fedb48379575ab1790533966a6156ea08b85fb0
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #22735: MNT: prefer Figure.clear() as canonical over Figure.clf()'
  1. Push to a named branch:
git push YOURFORK v3.5.x:auto-backport-of-pr-22735-on-v3.5.x
  1. Create a PR against branch v3.5.x, I would have named this PR:

"Backport PR #22735 on branch v3.5.x (MNT: prefer Figure.clear() as canonical over Figure.clf())"

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 Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

@timhoffm
Copy link
Member
timhoffm commented Apr 5, 2022

@tacaswell do you want to backport to 3.5.2? I think it's ok to leave this to 3.6.0.

@tacaswell tacaswell deleted the mnt_prefer_clear branch April 5, 2022 20:26
@tacaswell
Copy link
Member Author

There is a latent bug from #22138 , I'll see what the backport looks like.

tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Apr 5, 2022
… 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)
@tacaswell
Copy link
Member Author

This is backported as part of #22737

tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Apr 7, 2022
… 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)
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.

5 participants
0