Replies: 5 comments 11 replies
-
I don't belive it's worth switching from PEP-based docstrings to Google or Numpy. As for what's in the docstrings, I can't comment on that, as I don't know much about how the documentation is being generated(also I like MkDocs). But would keep it as lean as possible - I mean obvious things like don't write the type as the variables are type annotated, or just writing "Returns true if foo" instead of the whole ":returns:" stuff. |
Beta Was this translation helpful? Give feedback.
-
Isn't Also sphinx style uses |
Beta Was this translation helpful? Give feedback.
-
If I have to vote, I am a |
Beta Was this translation helpful? Give feedback.
-
Thanks much for the great overview, @happz! While we're speaking about the docstring conventions I'd like to suggest these two as well:
The first one could go to recommendations, the seconds could be covered by automated checks. |
Beta Was this translation helpful? Give feedback.
-
Wanted to share a tool that I've found that works with sphinx-style attribute docstrings (as well as all other formats): https://github.com/rr-/docstring_parser Might be interesting to incorporate Edit: Welp, I have been on a long rabbit-hole, basically it is currently impossible to attach docstrings to class attributes. The only "clean" way I've found was to add a |
Beta Was this translation helpful? Give feedback.
-
In the light of my attempt to enable (some) docstring checks in
ruff
linter, it would be nice to pick a docstring convention. Such a convention defines how various aspects of the documented object should be expressed in the docstring, e.g. function parameters or what it returns, but also defines (some) formatting requirements, e.g. whether a single-line docstring should indeed be written on a single line, or whether its leading & trailing triple quotes should sit on their own lines. We already accepted some rules, e.g. a single-line string shall occupy a single line, including its triple quotes, and shall not end with a dot, a convention would bring more of them.Note that this applies purely to docstrings, it's not that visible to users, unless they dive into the development part of docs generated from docstrings.
Cons:
Pros:
Conventions
PEP287 - reStructuredText Docstring Format
Basic "one shall use ReST to write their docstrings" rule. It does not discuss details of how attributes of documented objects would be expressed, only states that ReST is way better than plain text, and it should be adopted as the markup language of choice.
We are already on board, we don't use markdown or asciidoc in our docstrings. The discussion is about what to do beyond this basic setup.
PEP257 - Docstring Conventions
Sets some very, very basic rules - use triple quotes, a blank line here but not there, and so on. I believe we do have the basics covered, although we do not follow all the rules described in this PEP. For example:
I for one break this rule quite often as I find the "... or after the docstring" bit making code harder to read. A blank line separating a docstring and the actual code is nice to have in my books, and I've been following this consistently during my career, and there are parts of tmt code I did not touch that do add a blank line after a docstring.
Our single-line docstrings definitely do not end with a period...
I believe it's good to read these two PEPs, and be aware of their content, but we do not have to stick to them word by word. Especially the PEP257 which defines some conventions we already break and might be pretty happy to continue doing so in the future. We should be able to configure
ruff
to enforce our current style as exceptions to these basic rules.The gist of the discussion is IMO the convention for the description of various object attributes.
Sphinx Python domain
Builds upon PEP287 ("Use ReST") and defines ways to describe various aspects of documented objects, linking between them and other goodies provides by Sphinx.
Google
NumPy
As you can see, they are very similar in their use of ReST, but also different in their approach to actual attributes. Some are more verbose, some are denser. NumPy expects us to mention parameter types which is something that can be easily extracted from the signature (there's a Sphinx plugin for it, and we already use it), the other two do not require this.
5 votes ·
Beta Was this translation helpful? Give feedback.
All reactions