Sphinx remove dataclass fields from autodoc

1.3k Views Asked by At

As this post describes, autodoc will eagerly add the class variables to the documentation even if napoleon adds the fields as documentation in:

from dataclasses import dataclass
@dataclass
class Foo():
    """Some class

    Attributes:
        a: foo
        b: bar
    """
    a: str
    b: int

    def c(self) -> int:
        """Here's a doc'd function
        """
        return 3

I want to explicitly tell autodoc to not document any class variables (which is also instance variables in the case of dataclasses) - I only want autodoc to show declared functions for a given class and let napoleon handle the class/instance variables for all classes it finds. Is this possible without :exclude-members: for every class (which is a huge hassle)?

I already tried:

autodoc_default_options = {
    'members':          True,
    'undoc-members':    False,
}

in my conf.py and this in the .rst file:

.. automodule:: some.module
    :members:
    :show-inheritance:

Which should hide undocumented members but they still show up:

enter image description here

1

There are 1 best solutions below

0
EntangledLoops On

Just change Attributes: to Args:.