'Show docstring for inherited attributes in Sphinx autodoc

I have two classes, a base class and a class that inherits from this base class

from abc import ABC

class Base(ABC):
    """
    Base class
    
    Parameters
    ----------
    param1 : int


    Attributes
    ----------
    name : string
        identifier (not necessarily unique).
   
    """
    def __init__(self):
        self.name = "dummy_name"


class MyClass(Base):
    """
    Some other class 
    
    Parameters
    ----------
    param2 : int
   
    """

    def __init__(self):
        pass

and I want to inherit the attributes of the Base class into MyClass with autodocs. But it does not seem to work.

My autodoc config is like that :

extensions = [
    "sphinx.ext.doctest",
    "sphinx.ext.todo",
    "sphinx.ext.viewcode",
    "sphinx.ext.autodoc",
    "sphinx.ext.autosummary",
    "sphinx.ext.mathjax",
    "sphinx.ext.autosectionlabel",
    "sphinxcontrib.video",
    "numpydoc",
    "sphinx_gallery.gen_gallery",
    "myst_parser",
]


autodoc_default_options = {"members": True, "inherited-members": True, "show-inheritance":True}
# generate autosummary even if no references
autosummary_generate = True
autodoc_inherit_docstrings = True

and the class template is like that :

:mod:`{{module}}`.{{objname}}
{{ underline }}==============

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}

       
.. include:: {{module}}.{{objname}}.examples

.. raw:: html

    <div class="clearer"></div>

I tried to add :inherited-members: to the class template but it did not change anything.

PS: what I give here is a toy example, the project I document is much larger and would not fit into a question.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source