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

Skip to content

MAINT: Move docstring of LogLocator to class #22700

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 1 commit into from
Dec 16, 2022
Merged

Conversation

DerWeh
Copy link
Contributor

@DerWeh DerWeh commented Mar 24, 2022

Doc string is not accessible as it is placed in __init__ instead of class.

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

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

I think constructor parameters should be kept in __init__'s docstring (which can be accessed just as well via Foo.__init__.__doc__ or similar); see #17029 for rationale. (Probably this should be noted somewhere in the style guide.)

@DerWeh
Copy link
Contributor Author

DerWeh commented Mar 25, 2022

@anntzer The NumpyDoc style guide states, that the Parameters section of the class should detail the constructor arguments, see:
https://numpydoc.readthedocs.io/en/latest/format.html#documenting-classes

This is in accordance with the ecosystem, e.g., using LogLocator? in IPython displays only the class docstring, but not the LogLocator.__init__ docstring which you are interested in. The same goes for using hover of the python-lsp-server.

Personally, I want to know the constructor (__init__) parameters when I request the documentation. This was the reason I created this pull request. Most classes in matplotlib seem to respect the NumpyDoc style.

Duplicating the documentation in __init__ seems harder to maintain, but I'll just go with the convention matplotlib uses.

@anntzer
Copy link
Contributor

anntzer commented Mar 25, 2022

I don't really want to fight over this (even though I think documenting in __init__ just makes more sense, both in itself and also wrt inheritance), but if we decide to standardize on that, #17029 should be fixed accordingly.

@DerWeh
Copy link
Contributor Author

DerWeh commented Mar 25, 2022

I don't really care, either. But like I said, the NumpyDoc style says put it in the class docstring. Editors act accordingly. So if matplotlib would go against this convention, language servers would have to be changed, which I don't see as an option.


See the attached screenshots, the current situation is really annoying:

hover doesn't give useful information:
Screenshot from 2022-03-25 14-44-55
I have to write out __init__ instead and hover it, then delete it again:
Screenshot from 2022-03-25 14-45-21

That's so annoying that I opened the pull request. PercentFormatter is nice, here I just type it and immediately know which parameters I have to add:

Screenshot from 2022-03-25 14-46-35
Or the rendered version:
Screenshot from 2022-03-25 14-53-35


P.S.: https://github.com/python-lsp/python-lsp-server was used. If there are other language servers that handle numpydoc differently, please correct me.

@jklymak
Copy link
Member

jklymak commented Mar 29, 2022

@anntzer I think we would need a pretty good reason to not follow the numpydoc standard here, wouldn't we? Breaking in-editor documentation seems bad. I don't quite understand the problem in #17029 - is this a sphinx problem we are working around?

@jklymak jklymak added the status: needs comment/discussion needs consensus on next step label Mar 29, 2022
@anntzer
Copy link
Contributor

anntzer commented Mar 29, 2022

https://matplotlib.org/3.2.0/api/table_api.html#matplotlib.table.Cell is the "wrong" rendering (with doubled parameters docs). I'm not going to block this PR, just pointing out that we should try to avoid this kind of problems...

@jklymak
Copy link
Member

jklymak commented Mar 29, 2022

I'm not going to block this PR,

You are blocking this PR 😉 I agree that we can't have mis-rendered docs, I just wasn't clear if we had mis-rendered docs because of a sphinx bug, or us needing to do the docstring inheritance differently.

@anntzer anntzer dismissed their stale review March 29, 2022 11:53

Oopsie, forgot about that.

@QuLogic
Copy link
Member

QuLogic commented Mar 30, 2022

https://matplotlib.org/3.2.0/api/table_api.html#matplotlib.table.Cell is the "wrong" rendering (with doubled parameters docs).

It's doubled because we have configured Sphinx to display both class and __init__ docstrings, which has been the case since 2008 apparently. Most likely that's done because we aren't very consistent about putting them in one location. If everything were in e.g., the class docstring, we could reset that option to default (class) and see only one thing.

@jklymak
Copy link
Member

jklymak commented May 18, 2022

I'd propose we merge this. Suggest its a bunch of easy first contributions to clean up putting the docstrings in the class def....

@jklymak jklymak added this to the v3.6.0 milestone May 18, 2022
@DerWeh
Copy link
Contributor Author

DerWeh commented May 18, 2022

As there was some controversy here, we might consider adding some info to the documentation guidelines.

In principle, numpydoc is referred

All new or edited docstrings should conform to the numpydoc docstring guide.

so it should be fine. But if there is confusion, being explicit might be better, even if it is redundant.

@jklymak
Copy link
Member

jklymak commented May 18, 2022

I don't know if there is confusion per-se, just that our codebase developed somewhat before numpydoc even existed.

@jklymak jklymak added status: needs review and removed status: needs comment/discussion needs consensus on next step labels Jun 2, 2022
@QuLogic
Copy link
Member

QuLogic commented Jun 21, 2022

This needs a rebase now.

@timhoffm
Copy link
Member

timhoffm commented Jun 21, 2022

Note that the numpydoc standard (document __init__ in the class docstring) is violating PEP-257:

The docstring for a class should summarize its behavior and list the public methods and instance variables. [...] The class constructor should be documented in the docstring for its __init__ method.

So we might theoretically break other tools.

TL;DR Overall I'm +0.1 for class-docstring only

Should tools be able to cope with/wo __init__ docstrings? - Yes both

I've tested VSCode and PyCharm; both behave sanely with and without init docstring:

  • if init docstring: Show signature + init docstring
  • if no init docstring: Show signature + class docstring

Question: Does the python-lsp-server really identify numpydoc style? And then behave differently? I haven't checked but almost cannot belive that. If not they would in general not follow PEP-257. And that should be a reason to change the language server.

Do we want to change?

I'd say not just for the sake of fixing python-lsp-server. IMHO this issue is on them.

Other considerations for class-docstring only

  • There's only one place two write everything down. We don't have to rely on sphinx/numpydoc mangling this together in a meaningful way. --> +0.6
  • We fix python-lsp-server --> +0.2
  • We cannot inherit class and init docstrings independently. -> Possibly a bit more duplication. OTOH individual inheritance can also be unexpected. --> +0.3
  • Documenting the init parameters in that method docstring is more natural. --> -1

Overall I'm +0.1 for class-docstring only

@jklymak
Copy link
Member

jklymak commented Jun 23, 2022

I've added this to the call....

@jklymak jklymak marked this pull request as draft June 23, 2022 08:17
@tacaswell tacaswell modified the milestones: v3.6.0, v3.7.0 Aug 19, 2022
@dstansby
Copy link
Member

@jklymak don't suppose you remember if a decision was reached or documented here?

@jklymak
Copy link
Member

jklymak commented Dec 15, 2022

@dstansby No I don't recall what was decided, if anything.

@tacaswell tacaswell marked this pull request as ready for review December 16, 2022 20:50
Doc string is not accessible to some IDE tools if it is placed on `__init__`
instead of on class.
@tacaswell
Copy link
Member

I propose we merge this and open a new issue to document (and enforce uniformly) where this should go.

Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

👍 - thanks a lot @DerWeh for this contribution, and really sorry it got bogged down in a long conversation before being merged.

@dstansby dstansby merged commit 4945f05 into matplotlib:main Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

7 participants