-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Additional docstring recommendations #10225
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
I have an implementation of a custom
and get this mapped to, well, whatever we want. The nice thing is that roles can be in the postfix position too, so we could even have a construct such as
which seems very readable and lightweight in plain text. The PR depends on #9708 though so I'll wait for that PR to be merged first. Edit: actually not that hard to split out, see #10226. For array(-like) parameter type descriptions we should probably use something close-ish to numpy's current effort (python/typing#516 and stuff linked therein). |
Note: handling of parameter lists updated: #10280 |
Also, I think I prefer float to scalar, even though it is a slight abuse of language to make it mean "float-or-int" (I guess if you want to be really pedantic we usually mean https://docs.python.org/3/library/numbers.html#numbers.Real anyways...). |
👍 all of these seem eminently reasonable. |
I will recheck what other scientific libraries are using. It makes sense to try and use a common language. Then I will provide a pull request. |
Proposal for array-like typesThere is no strict consensus among or even within other scientific libraries (checked numpy, scipy, pandas). The prevalent form is a variant of "array-like". So, I propose
|
I have continued to edit some docstrings (figure and pyplot) and I believe that after some confusion it is quite clear how to write. A few question though. Are there any convention for how to write True, False and None? I believe that they are written in all possibles ways in the docstrings. I think doing nothing special works well but single back ticks gets a link to the python documentation and looks good. How to write example code in the docstrings? With Things that have been confusing to me are if the markups, :class:, 'func: etc, should be used or not. I realize now that a section in the documentation where about those but I thought markups there meant some other markup. I also got confused that back ticks should not be used in the |
Personally, I currently use
:class: etc should be left out where possible to improve readability (i.e. where there is not an ambiguity in the name). I'm not quite sure right now about |
Ok, some other comments in regard to kwargs and what to link to. I found it frustrating that the Axes kwargs are not included in the natural place in the documentation. Wouldn't it be better to just make some kind of hack to get them into the documentation compared to waiting for someone writing a good solution? I also looked at the Axes string that can be used in How to link to the documentation when subclasses are involved? axes are often not What about including What is the best way to look at very long docstrings? edit: Are there really any reason to include the kwargs list in methods? For example in plot The table is one click away in the docs and the table often looks bad in a shell and makes the docstring much longer. |
I cannot really say something on the Axes topic. Didn’t have time to look into it yet.
Not sure what you mean with that. HTML page? The kwarg tables are debatable. They’ve been around for a long time. On the plus side, it’s more obvious which values are supported. With a link, you’d still have to follow the link and find the relevant part of the target docstring (the link goes to the top of the docstring not to the list). That’s not impossible, but a distraction. On the shell (or in jupyter notebooks) you don’t have the link and it’s difficulty get the information there. Therefore, I’m +0.5 on keeping the kwarg lists. |
Most of the recommendation have been incorporated into the documentation guide. Currently, I don't see the need for further work. |
as a followup to #9786 and more generally #7217
Update: Striked through done
Proposal: Additional docstring recommendations
While looking at and writing more documentation, I've come across different conventions in several aspects of the docstrings.
While one should not be too pedantic, and the world does not end if there are some variations, a set of of recommendations helps.
Structure of this proposal
For every aspect, if written a text to be included in documentation guide in quotes:
Everything else are descriptions of the current state or explanations. One may consider adding the rationales.
Parameter type descriptions
#### Number typeProposal:
Current usage: Already often done, but not always. Just a hint for new writers.#### array-like inputsFor array-like inputs, there are several notations:
Additionally, there are many variants to note length or dimensionality:
Note: according to this journal article 3D is more commonly used than 3-D.
String values
e.g.
Rationale: For the rendered docs, a litterally-quoted string
``'none'``
would look a bit nicer (similar to'none'
), but that's too difficult to type and too difficult to read in plaintext docs.Current usage: Already often done, but not always. Just a hint for new writers.
### Citing other typesDo we use
~matplotlib.markers.MarkerStyle
or.MarkerStyle
?Proposal:
e.g.
Rationale: The distinction is only relevant for the plaintext string. The full reference is required if I want to find the corresponding doc (e.g. ipython
matplotlib.colors.Normalize?
). Therefore we write it in the type definition. In a text passage, readability has a higher priority. Therefore, we use abbreviated references.e.g.
Rationale: The abbreviated from in the HTML should be easy to read. The link target gives the exact reference.### Citing rcParamsCurrent variants:
``(lines.linewidth,)``
``image.cmap``
/ defaults to rc`image.origin`
``hist.bins``
``rcParams['lines.markersize'] ** 2``
We should create a label
.. _rc-params
here.e.g.
Rationale: A link to the rcParams is helpfull, but it should be as short as possible in the plain text. One could also :ref:rc-params
, but the link text would then depend on the section titile, which may not be good.Note: If we would switch from the Sphinx default_role
obj
toany
, we could even leave out the:ref:
.Note 2: The object
rcParams
is currently sometimes referenced, but that does not contain a list and description of the values. Also, there are several ways to influence the rcParams. So the above reference is more appropriate than the object. We should add a link from the object.Spaces after colon
Just noted that sometimes there's one space, sometimes there are two spaces. Not sure if it's worth mentioning.
The text was updated successfully, but these errors were encountered: