Skip to content
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

Inherit docstrings for class attributes #55

Open
embray opened this issue Apr 10, 2015 · 3 comments
Open

Inherit docstrings for class attributes #55

embray opened this issue Apr 10, 2015 · 3 comments

Comments

@embray
Copy link
Member

embray commented Apr 10, 2015

Sphinx provides a mechanism, which is not normally supported in Python, to provide docstrings for class attributes and module-level variables. We use this in several places in Astropy to document such objects. The syntax places a docstring immediately after the variable/attribute is defined like:

answer = 42
"""Answer to the question of life, the universe, and everything."""

Sphinx can pick these up and add docs for the answer variable to the documentation for whatever module or class it's defined in.

Astropy has a metaclass called InheritDocstrings which allows subclasses to automatically inherit docstrings from their base class for any members they override (and for which they do not explicitly provide docstrings). However, this mechanism doesn't work for class attributes since there isn't any officially supported way to handle them in Python. And would be nice to write a Sphinx extension and/or patch to Sphinx to make this work properly.

@hamogu
Copy link
Member

hamogu commented Jan 21, 2016

👍

@astrofrog astrofrog transferred this issue from astropy/astropy-helpers Dec 4, 2018
@pllim
Copy link
Member

pllim commented Feb 22, 2021

Sphinx now does this natively but doesn't seem to work with automodapi? https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_inherit_docstrings

@pllim
Copy link
Member

pllim commented Feb 22, 2021

If I set autodoc_inherit_docstrings = True in conf.py and use autoclass, it works, but not with automodapi.

@pllim pllim changed the title Inhert docstrings for class attributes Inherit docstrings for class attributes Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants