Sphinx Autodoc skip member from docstring Sphinx Autodoc skip member from docstring python python

Sphinx Autodoc skip member from docstring


You can now (as of version 0.6) use :exclude-members: to exclude specific members from the documentation:

The directives supporting member documentation also have a exclude-members option that can be used to exclude single member names from documentation, if all members are to be documented.

New in version 0.6.

Source: http://www.sphinx-doc.org/en/stable/ext/autodoc.html

In your specific case, you would add :exclude-members: log into your .rst file.


There doesn't appear to be any easy way to do this.

As a workaround, you can try something like this in your RST file:

.. autoclass:: StatusUpdateAdapter   :members: methodA, methodB

But that requires listing out all the methods you do want to document by hand, which could be quite laborious. It also probably doesn't interact well with :inherited-members:, if you're using that.

Another option is to put a docstring on every method you want documented, but no docstring on the log() method, then (if necessary) use :no-undoc-members:. This is obviously no good if you plan on documenting your internal interfaces or not documenting your public interfaces.

Finally, Autodoc skips anything whose name begins with an underscore unless configured otherwise (:private-members:), so if you use an underscore-prefixed name, the method will not appear. Underscore-prefixing indicates a private interface under PEP 8, which may or may not match up with your intentions. This could also create backwards compatibility headaches in an established codebase.


I'm not sure how to do that with a docstring, but you can declare the function/method 'protected' with a prepended underscore. Sphinx will not pull that function/method in.

def _log(self, *args, **kwargs):     pass