-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Consistent Documentation Guide for Docstrings #9786
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
Comments
As a new contributor, I think I agree w/ most of this. As a stop-gap, it'd be really useful to have a couple of gold-standard examples to look at... |
I agree this is confusing and apologize if my comments on your PR came out as too dry. I already have two PRs regarding the docs on docs and would prefer them to go in before more changes are applied (otherwise the conflicts become a mess). But briefly:
Single backticks mean "a python object that has its own linkable entry in the docs" (technically, the py:any role -- we're not making this up, it's RST+Sphinx!). Function arguments and keywords do not have freestanding entries in the docs, so they need to be marked in another way. Double backticks on both sides (which have the same meaning as single backticks in markdown, i.e. "literal") is probably the most technically correct, but it's a bit heavy and italics (emphasis) works just as well.
Leave as is.
I would suggest first checking the rendered docs (http://matplotlib.org/devdocs/api/index.html) and then adding the markup only if necessary -- remember that people also look directly at the unrendered docstring (source/ipython/pydoc) so excessive markup can be distracting.
Sphinx will only recognize a call signature on the first line exactly, but we have some functions with (excessively) complicated signatures, so in that case we need to do it manually (but only in these cases). For the specific case of |
Bug report
Summary
The documentation guide contains a section about docstrings. Unfortunately, in my attempt to add / improve some docstrings I found it largely deficient.
This issue collects the problems I encounted and may serve as a starting point to improve the API docs.
Motivation
A good documentation is essentially for the usability of a library. Even more so, for a large library with many options and making heavy use of
*args
and**kwargs
.To get improvements here, there has to be a consistent and easily understandable style guide. Otherwise, contributors will not know or bother.
Issues
The docstrings section is outdated and thus misleading.
better:
numpydoc does not fully cover all aspects of docstrings. Some should be clarified on the project level.
Handling of
*args
and**kwargs
: Should they be Parameters, Other Parameters or something else?Handling of long lists of value choices:
See here:
When to use abc,
abc
, 'abc', "abc",abc
. In particular also usage of double or single quotes in the docs (even if it's: Do as you like but don't change existing stuff). Indicate if these decisions deviate intentionally from other sources you link (e.g. numpy: "Variable, module, function, and class names should be written between single back-ticks (numpy
)", vs Formatting: "Function arguments and keywords should be referred to using the emphasis role."When to cross reference and when not "Types don't need to be marked up." vs "Sometimes sphinx doesn't automatically put in links with out the markup though." See here Also if sphinx has a bug that return values are not always cross-referenced, mention that and your policy (Either keep plain types, it will be fine once sphinx is fixed. Or add reference now, we can strip it later).
Usage of call signature: Some methods have this, others not.
The text was updated successfully, but these errors were encountered: