0

Currently, I am describing module as:


.. autoclass:: package.module.class
   :members:
   :undoc-members:
   :show-inheritance:
   :private-members:
   :member-order: bysource

And it shows all members in a row. I want to do something as:


.. autoclass:: package.module.class
   :members:
   :undoc-members:
   :show-inheritance:
   :member-order: bysource

Private methods
===============

.. autoclass:: package.module.class
   :noindex:
   :private-members:
   :member-order: bysource

I had to use :noindex: because of that:

WARNING: duplicate object description of package.module, other instance in class, use :noindex: for one of them

But it seems that :private-members: does not show without :members:. This code will show nothing except class object docstring:

.. automodule:: package.module.class
   :noindex:
   :private-members:
   :member-order: bysource

And this stuff will show all class methods:

.. automodule:: package.module.class
   :noindex:
   :members:
   :private-members:
   :member-order: bysource

How to show private-members without showing other stuff?

banderlog013
  • 2,207
  • 24
  • 33
  • Just in case -- what's the error that you get when you try to do what you've done? – user202729 Aug 17 '21 at 12:55
  • @user202729 sorry, "WARNING: duplicate object description of package.module, other instance in module, use :noindex: for one of them" – banderlog013 Aug 17 '21 at 13:09
  • Well, it's just a warning not an error. (read documentation of noindex to figure out what it does) Otherwise it still works right? – user202729 Aug 17 '21 at 13:10
  • nope, after adding `:noindex:` in one of them -- it will not appear in the generated doc. But, as I figured out, just because `:private-members:` does not show without `:members:` – banderlog013 Aug 17 '21 at 13:20
  • 1
    Huh, looks like you figured out the issue. See [Showing only private methods with Sphinx' Autodoc - Stack Overflow](https://stackoverflow.com/questions/57610288/showing-only-private-methods-with-sphinx-autodoc) – user202729 Aug 17 '21 at 13:25

1 Answers1

0

This doesn't directly answer your question, but I wrote a Sphinx plugin called autoclasstoc for the exact purpose of visually separating public and private methods in class documentation. The basic idea of the plugin is to create a list of links to all the attributes of the class, organized into sections such as Public/Private, Attributes/Methods, Inherited from <ParentClass>, etc. The detailed documentation for each attribute remains in alphabetical order, but the organized list makes the structure of the class clear.

Here's an example of the syntax you would use with this plugin. It's just a one-line addition to what you already have:

.. autoclass:: package.module.class
     :members:
     :undoc-members:
     :show-inheritance:
     :private-members:
     :member-order: bysource

     .. autoclasstoc::
Kale Kundert
  • 1,144
  • 6
  • 18