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

Skip to content

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

Closed
6 tasks
timhoffm opened this issue Nov 14, 2017 · 2 comments · Fixed by #9805
Closed
6 tasks

Consistent Documentation Guide for Docstrings #9786

timhoffm opened this issue Nov 14, 2017 · 2 comments · Fixed by #9805
Milestone

Comments

@timhoffm
Copy link
Member

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

  1. Multiple sources
  1. Outdated directions

The docstrings section is outdated and thus misleading.

In addition to the “narrative” documentation described above, matplotlib also defines its API reference documentation in docstrings. For the most part, these are standard Python docstrings, but matplotlib also includes some features to better support documenting getters and setters.

better:

In addition to the “narrative” documentation described above, the API reference documentation is generated from docstrings in the code. Generally, matplotlib uses numpy style docstrings [link]. To further enhance the documentation we have augmented numpy style by some additional conventions and features.

Additional Conventions:

Additional Features: [existing stuff here]

  • Remove outdated stuff. Add placeholders and notes if there are some known gaps.
  1. Additional Conventions

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:

projection :
            ['aitoff' | 'hammer' | 'lambert' | 'mollweide' | \
'polar' | 'rectilinear'], optional
  • 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.

    Call signature::

      text(x, y, s, fontdict=None, **kwargs)
  1. Migration of documentation
  • State that there's still a mixture of old and new styles and that the migration is ongoing.
  • List deprecated conventions and how to replace them.
  1. Examples
  • Add examples in the above parts as much as possible. They are more instructure than lengthy texts.
  • Link to parts of code with good documentation, from which one can learn.
@tacaswell tacaswell added this to the v2.2 milestone Nov 14, 2017
@jklymak
Copy link
Member

jklymak commented Nov 15, 2017

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

@anntzer
Copy link
Contributor

anntzer commented Nov 15, 2017

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:

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

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.

Quotes

Leave as is.

Types markup

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.

Call signature

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 text that could probably be reworked indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants