Skip to content

DOC: make legend docstring interpolated #10799

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
Mar 18, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Mar 15, 2018

PR Summary

The three legend docstrings (legend.py, ax.legend, fig.legend) have the same "Other Parameters" section. These had drifted apart over the years (as had their acceptable kwargs). We unified them #9324, but there was some protest about using the docstring interp method, so I cut and pasted the docstrings, and added a test to test_legend that made sure the strings were identical.

Not surprisingly, this has caused problems. The test routinely fails when someone has edited one of the three docstrings. Good, its catching inconsistencies, but its a bit hard to tell folks to cut and paste the same thing three time.

I (somewhat strongly) think docstring interpolation is the better option here. Faced with the mysteries of %(_legend_kw_doc)s I think its save to assume the naive user will search the code base for this string and see thats where to put their new description of (yet another) kwarg for legend.

Could be convinced that just referencing legend.__init__ would be OK, but I do like the kwargs to appear in the local docstring.

PR Checklist

  • Code is PEP 8 compliant
  • Documentation is sphinx and numpydoc compliant

@jklymak
Copy link
Member Author

jklymak commented Mar 15, 2018

https://7779-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/api/legend_api.html

Does "Other Parameters" not behave the same as Parameters? Or is this an indenting issue?

@jklymak
Copy link
Member Author

jklymak commented Mar 15, 2018

OTOH, this looks the same as the current docs, so I'll argue is an improvement.

https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.legend.html#matplotlib.axes.Axes.legend

@jklymak jklymak added this to the v3.0 milestone Mar 15, 2018
@timhoffm
Copy link
Member

Does "Other Parameters" not behave the same as Parameters? Or is this an indenting issue?

It should behave the same. Probably an indenting issue.

@jklymak
Copy link
Member Author

jklymak commented Mar 16, 2018

OK, well, I'll try to hack until its fixed...

@jklymak
Copy link
Member Author

jklymak commented Mar 16, 2018

@timhoffm when I had this stuff hardcoded in (before this change) it also failed to look the same as Parameters. So, I'm not sure this PR isn't OK as is, though I'd be happy to fix the issue if its easy to fix.

@jklymak jklymak force-pushed the doc-interp-legenddocstring branch from 9b359ce to da1763c Compare March 16, 2018 01:21
@timhoffm
Copy link
Member

@jklymak
Copy link
Member Author

jklymak commented Mar 16, 2018

I agree with that. But it had issues before this PR as well. Ie look at the current version of the docs (linked above).

So the problem isn’t the docstring interpolation.

OTOH I’m willing to fix the problem, I just have no idea what it is

@jklymak
Copy link
Member Author

jklymak commented Mar 16, 2018

@timhoffm all the "Other Parameter" blocks look like this one: i.e. https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.text.html#matplotlib.axes.Axes.text

So I think thats just how other-parameters ends up looking.

@timhoffm
Copy link
Member

@jklymak Do you mean that the grey bar extends to the right instead of down? This is probably a bug in numpydoc. See #6924.

@jklymak
Copy link
Member Author

jklymak commented Mar 16, 2018

@timhoffm Thats indeed what I meant.

This PR doesn't make the formatting worse, and makes the docstring currating substantially easier. The "Other Parameters" bug is a different battle.

The custom dictionary mapping instances or types to a legend
handler. This `handler_map` updates the default handler map
found at :func:`matplotlib.legend.Legend.get_legend_handler_map`.
%(_legend_kw_doc)s
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I see what you and @timhoffm mean now - you mean in the Parameter section above this change. Silly me, only checking the part of the doctoring I edited...

I cannot see why either. Very strange as the Axes.legend and Figure.legend docstrings are fine, and I don't see how they are any different than this doctoring...

@@ -348,7 +348,6 @@ def __init__(self, parent, handles, labels,
handler_map=None,
):
"""

Copy link
Member Author

Choose a reason for hiding this comment

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

This extra space was causing the hiccup in the formatting. Sphinx is pretty fragile....

@jklymak
Copy link
Member Author

jklymak commented Mar 17, 2018

@timhoffm timhoffm merged commit 4257416 into matplotlib:master Mar 18, 2018
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.

4 participants