Opened 4 years ago
Last modified 4 years ago
#5120 closed defect
(Various modules) Malformed docstrings — at Version 1
| Reported by: | Zach Pearson | Owned by: | Zach Pearson |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | Documentation | Version: | |
| Keywords: | Cc: | ||
| Blocked By: | Blocking: | ||
| Notify when closed: | Platform: | all | |
| Project: | ChimeraX |
Description (last modified by )
While looking at what it would take to tackle this ticket https://www.rbvi.ucsf.edu/trac/ChimeraX/ticket/782 I started looking at the warnings thrown by the build system when creating the documentation. If you've reinstalled the list_info and ui bundles lately, you might notice they're gone!
I find myself using the developer documentation and occasionally see some docstrings that are poorly formatted. If I look at the code the reason is often that they're using Google or NumPy style docstrings or have a strange space between the parameter name and the parameter description, with a unified parameter list that doesn't convert properly when Sphinx reads the file. There's an extension for that:
https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
which lets those docstrings be read and converted to the usual verbose docstrings without input on our part. The additional benefit is that in future docstrings, it lets us be less verbose and still get good documentation.
Second, I'm always writing code with type hints and I don't think it's good to have to repeat the type in the docstring for it to be picked up by Sphinx. I also don't really like the giant signature that gets generated online by default; the spacing is weird.
Adding this extension:
https://github.com/agronholm/sphinx-autodoc-typehints
Results in much better looking output.
I don't think it's necessary to turn it into a big project. Probably enabling these two packages and working as normal, the problem will eventually solve itself.
Change History (7)
by , 4 years ago
| Attachment: | original_docs.png added |
|---|
by , 4 years ago
| Attachment: | docstrings_correct_but_malformed_code.png added |
|---|
Docstrings with type-hinted function signature, and removing the space after the parameter to the class constructor
by , 4 years ago
| Attachment: | docstrings_correct_but_malformed_no_napoleon.png added |
|---|
Ugly output after adding type hints and removing the space between the constructor parameter and colon
by , 4 years ago
| Attachment: | docstrings_with_napoleon.png added |
|---|
Docstrings after enabling just the Napoleon extension; the constructor's documentation is fixed but create_child_window still looks bad
by , 4 years ago
| Attachment: | with_napoleon_and_autodoc_typehints.png added |
|---|
Docstrings after enabling sphinx.ext.napoleon and sphinx_autodoc_typehints
comment:1 by , 4 years ago
| Description: | modified (diff) |
|---|
Original example documentation