Opened 4 years ago

Closed 4 years ago

#5120 closed defect (fixed)

(Various modules) Malformed docstrings

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 Zach Pearson)

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.

Attachments (6)

original_docs.png (92.3 KB ) - added by Zach Pearson 4 years ago.
Original example documentation
original_docstrings.png (100.6 KB ) - added by Zach Pearson 4 years ago.
Original docstrings
docstrings_correct_but_malformed_code.png (79.4 KB ) - added by Zach Pearson 4 years ago.
Docstrings with type-hinted function signature, and removing the space after the parameter to the class constructor
docstrings_correct_but_malformed_no_napoleon.png (94.0 KB ) - added by Zach Pearson 4 years ago.
Ugly output after adding type hints and removing the space between the constructor parameter and colon
docstrings_with_napoleon.png (91.9 KB ) - added by Zach Pearson 4 years ago.
Docstrings after enabling just the Napoleon extension; the constructor's documentation is fixed but create_child_window still looks bad
with_napoleon_and_autodoc_typehints.png (91.4 KB ) - added by Zach Pearson 4 years ago.
Docstrings after enabling sphinx.ext.napoleon and sphinx_autodoc_typehints

Download all attachments as: .zip

Change History (10)

by Zach Pearson, 4 years ago

Attachment: original_docs.png added

Original example documentation

by Zach Pearson, 4 years ago

Attachment: original_docstrings.png added

Original docstrings

by Zach Pearson, 4 years ago

Docstrings with type-hinted function signature, and removing the space after the parameter to the class constructor

by Zach Pearson, 4 years ago

Ugly output after adding type hints and removing the space between the constructor parameter and colon

by Zach Pearson, 4 years ago

Docstrings after enabling just the Napoleon extension; the constructor's documentation is fixed but create_child_window still looks bad

by Zach Pearson, 4 years ago

Docstrings after enabling sphinx.ext.napoleon and sphinx_autodoc_typehints

comment:1 by Zach Pearson, 4 years ago

Description: modified (diff)

comment:2 by Tom Goddard, 4 years ago

Would be great to have improved format programmer documentation. I see differences when argument type specifiers are present, but we don't use those much (so far). So I am more interested in what other format changes you propose. Let's discuss at next week's developer meeting. We will need to have examples to look at so if you (Zach) could screen share some examples during the meeting and explain the advantages that would be good.

Thanks for fixing up the doc parsing errors. I have done that many times in the past but new ones are always cropping up.

Our programmer doc strings use a variety of different formats in the doc strings producing different formats in the online docs and it would be good if we stuck with one style.

comment:3 by Zach Pearson, 4 years ago

Disabling numpydoc and enabling napoleon resulted in a handful of new formatting warnings that had to be corrected, but they weren't that difficult. Checked a few pages to ensure they looked normal then enabled sphinx_autodoc_typehints and didn't find any breakages. I think I can say with relative confidence that any formatting issues that have yet to be discovered are not due to napoleon/sphinx_autodoc_typehints.

comment:4 by Zach Pearson, 4 years ago

Resolution: fixed
Status: assignedclosed

Merged sphinx_napoleon_typehints into develop.

Note: See TracTickets for help on using tickets.