python sphinx autodoc exclude __init__

83 Views Asked by At

I have 2 classes. Class1 needs to display all docstrings, while Class2 needs to display only method docstrings. In the following example, I am trying to disable Class2 without success, docstrings of Class2 still displayed. Please help me disable class and init docstrings in Class2.

conf.py

autoclass_content = "both"

index.rst

Title
=====

.. autoclass:: classes.Class1
  :members:

.. autoclass:: classes.Class2
  :members: method
  :exclude-members: __init__, __weakref__

classes.py


class Class1:
    """Docstring1"""

    def __init__(self):
        """Init1"""

    def method(self):
        """Method1"""


class Class2:
    """Docstring2"""

    def __init__(self):
        """Init2"""

    def method(self):
        """Method2"""

expected result

Title

class classes.Class1
    Docstring1
    Init1

    method()
        Method1

class classes.Class2

    method()
        Method2

actual result

Title

class classes.Class1
    Docstring1
    Init1

    method()
        Method1

class classes.Class2
    Docstring2
    Init2

    method()
        Method2
0

There are 0 best solutions below