3

I am using the Sphinx autodoc extension for documenting my Python project. I have the following in my docs for a class:

.. automodule:: ClassName
    :members:
    :undoc-members:
    :show-inheritance:

The class I am documenting has static members which I don't want to include in documentation. Is there any way to do so?

mzjn
  • 48,958
  • 13
  • 128
  • 248

1 Answers1

-1

See the documentation of the option :exclude-members: under .. automodule:: for usage.

You need to add the option :exclude-members: member1, member2

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
  • I already have checked the documentation of `:exclude-members:` but by using it only single member names can be excluded. I have around 6-7 static methods which I need to exclude at once. – Sandeep Mahapatra Jul 21 '17 at 16:59
  • I think you misinterpreted the meaning. Separate the single members with commas, i.e., `:exclude-members: member1, member2` – Steve Piercy Jul 21 '17 at 18:53
  • Okay. But is there any way in which we can say to exclude all static members without having to mention them one by one? – Sandeep Mahapatra Jul 22 '17 at 19:39
  • Not that I know of in a direct manner. You could remove docstrings from static members, then remove `:undoc-members:` from the reST source, but that's hacky. Suggest [submitting an issue](https://github.com/sphinx-doc/sphinx/issues) to discuss adding this feature to Sphinx, or searching through the issue tracker to see if it's already suggested or solved. – Steve Piercy Jul 22 '17 at 21:09
  • @StevePiercy Couldn't he implement a user-defined `skip_member_handler` to skip static methods? I'm using such a handler to document e.g. marked `__init__` methods. – Paebbels Jul 24 '17 at 21:02
  • @Paebbels I considered that, but I don't know how to determine whether a member is static or not, or if it is possible. Maybe someone more experienced knows. If there is a way to make that distinction, then the Sphinx documentation on [Skipping Members](http://www.sphinx-doc.org/en/stable/ext/autodoc.html#skipping-members) provides the interface for a user-defined method. – Steve Piercy Jul 25 '17 at 00:02
  • 1
    The representation of a static method's type returns `` instead of `` for a normal method. Example: `print(type(myclass.mystaticmethod))` I think the module `inspect` (Python introspection API) should give more and better details. See also here: https://stackoverflow.com/questions/8727059/python-check-if-method-is-static – Paebbels Jul 25 '17 at 05:07