Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Shorten implementation of Axes methods that just wrap Axis methods. #16903

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 4 commits into from
Apr 6, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Mar 25, 2020

... by autogenerating wrappers that forward to the Axis methods.

Admittedly docstring search/replace is a bit ugly, but this has to be
compared with having 4 copies of the docstrings for each method (Axis,
xaxis, yaxis, zaxis) each to be kept in sync.

(As an anecdote, the ability to do this templatization for mplot3d was what originally motivated me to check whether minor ticks could easily be fixed for 3d axes...)

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added this to the v3.3.0 milestone Mar 25, 2020
@anntzer anntzer force-pushed the templatize-axiswrappers branch 3 times, most recently from de876cc to 61c99b6 Compare April 4, 2020 12:05
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

I like this. It also helps make sure that pass-throughs remain pass-throughs

Makes the judgement in #17028 to do it on the Axis even more persuasive.

@anntzer
Copy link
Contributor Author

anntzer commented Apr 4, 2020

I pushed a slightly different implementation (directly lifting the "Placeholder" class out) and left some comments explaining why this relies on __set_name__ and how it works.

to the ``get_bar`` method of the ``xaxis`` attribute, and gets its
signature and docstring from ``Axis.get_bar``.

The docstring of ``get_foo`` is built by replacing "this Axis" by "the
Copy link
Member

Choose a reason for hiding this comment

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

I'm slightly worried that subsequent edits on the docstring will break this clever replacements. People usually won't know that "this Axis" has a special meaning. They could easily write:

  • this axis
  • this `.Axis`
  • the axis

I'm afraid that we can't do much in terms of documenting this for docstring authors or warning upon processing. But let's at least include the first two variants for replacement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather keep things consistent. Note that there is an assertion check that the correct substring is present, with a hopefully clear error message -- and the check occurs at import time, so we'd easily catch it in CI.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I did not realize the assert.

@anntzer anntzer force-pushed the templatize-axiswrappers branch from 98534b6 to aab2b3f Compare April 5, 2020 18:03
to the ``get_bar`` method of the ``xaxis`` attribute, and gets its
signature and docstring from ``Axis.get_bar``.

The docstring of ``get_foo`` is built by replacing "this Axis" by "the
Copy link
Member

Choose a reason for hiding this comment

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

Ok, I did not realize the assert.

@timhoffm
Copy link
Member

timhoffm commented Apr 5, 2020

Lot's of warnings in the sphinx build

/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.BarAB:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Bracket
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.BracketA:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Bracket
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.BracketAB:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Bracket
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.BracketB:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Bracket
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.Curve:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Curve
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.CurveA:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Curve
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.CurveAB:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Curve
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.CurveB:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Curve
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.CurveFilledA:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Curve
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.CurveFilledAB:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Curve
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.CurveFilledB:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Curve
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.Fancy:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.Simple:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ArrowStyle.Wedge:1: WARNING: py:class reference target not found: matplotlib.patches.ArrowStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.Circle:1: WARNING: py:class reference target not found: matplotlib.patches.BoxStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.DArrow:1: WARNING: py:class reference target not found: matplotlib.patches.BoxStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.LArrow:1: WARNING: py:class reference target not found: matplotlib.patches.BoxStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.Round:1: WARNING: py:class reference target not found: matplotlib.patches.BoxStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.Round4:1: WARNING: py:class reference target not found: matplotlib.patches.BoxStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.Sawtooth:1: WARNING: py:class reference target not found: matplotlib.patches.BoxStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.Square:1: WARNING: py:class reference target not found: matplotlib.patches.BoxStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ConnectionStyle.Angle:1: WARNING: py:class reference target not found: matplotlib.patches.ConnectionStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ConnectionStyle.Angle3:1: WARNING: py:class reference target not found: matplotlib.patches.ConnectionStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ConnectionStyle.Arc:1: WARNING: py:class reference target not found: matplotlib.patches.ConnectionStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ConnectionStyle.Arc3:1: WARNING: py:class reference target not found: matplotlib.patches.ConnectionStyle._Base
/home/circleci/project/lib/matplotlib/patches.py:docstring of matplotlib.patches.ConnectionStyle.Bar:1: WARNING: py:class reference target not found: matplotlib.patches.ConnectionStyle._Base
/home/circleci/project/lib/mpl_toolkits/axisartist/axisline_style.py:docstring of mpl_toolkits.axisartist.axisline_style.AxislineStyle.SimpleArrow:1: WARNING: py:class reference target not found: mpl_toolkits.axisartist.axisline_style.AxislineStyle._Base
/home/circleci/project/lib/mpl_toolkits/axisartist/axislines.py:docstring of mpl_toolkits.axisartist.axislines.AxisArtistHelper.Fixed:1: WARNING: py:class reference target not found: mpl_toolkits.axisartist.axislines.AxisArtistHelper._Base
/home/circleci/project/lib/mpl_toolkits/axisartist/axislines.py:docstring of mpl_toolkits.axisartist.axislines.AxisArtistHelper.Floating:1: WARNING: py:class reference target not found: mpl_toolkits.axisartist.axislines.AxisArtistHelper._Base

I think they are unrelated, but not sure about it.

Edit: Same warnings in #17021. Either we have commited something that breaks these or it's caused by sphinx 3.0.0, which has been released a couple of hours ago.

@anntzer
Copy link
Contributor Author

anntzer commented Apr 5, 2020

I'd believe it's something to do with sphinx 3.0, but I'm fine waiting for that to be handled first (e.g. by temporarily pinning to <3.0) before merging this.

Edit: rebased over the sphinx fix.

anntzer added 4 commits April 6, 2020 17:14
... by autogenerating wrappers that forward to the Axis methods.

Admittedly docstring search/replace is a bit ugly, but this has to be
compared with having 4 copies of the docstrings for each method (Axis,
xaxis, yaxis, zaxis) each to be kept in sync.
@anntzer anntzer force-pushed the templatize-axiswrappers branch from aab2b3f to 1f62d29 Compare April 6, 2020 15:14
@timhoffm timhoffm merged commit 348e9fe into matplotlib:master Apr 6, 2020
@anntzer anntzer deleted the templatize-axiswrappers branch April 6, 2020 17:28
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