I am putting together Sphinx-driven (v1.3.1) documentation for a Python 2.7 project using autodoc and napoleon. Inside one module, which I'd like to document with a single automodule:: directive, I have a specific class to which I want to apply the :special-members: flag. Flagging the automodule:: with :special-members: shows the specials for everything in the module, and that's no good.
How can I do this?
Adding an autoclass:: directive flagged with :special-members: still leaves the "non-specialized" documentation there as part of the automodule:: content, resulting in duplicated content.
I suppose I could explicitly type out all of the classes in the module except my specials-targeted one in a :members: instruction on the automodule::, but then I'd have to remember to update that list every time I added or removed a class to the module.
The solution for this is excluding the members that you want different options applied to in
automodule. Afterwards include them with their own directive, setting the particular options you want on that directive.The following example excludes
ClassBfrom theautomoduledirective. AfterwardsClassBis included in the context of theautomodulewith its ownautoclassdirective. Under the:special-members:option set only the members you want shown.Corresponding
.rstfile:Corresponding
.pyfile:This minimizes the number of exceptions you have to type because default rules still apply normally to the remaining members of the module, except when you indicate otherwise. In most IDEs this solution will also refactor changes made to the Python source code.
For the exact solution shown
special-membersandprivate-memberswere not included inautodoc_default_optionsinsideconf.py. The relevant sphinx.ext.napoleon setting was set tonapoleon_include_special_with_doc = False. However, the individual directive settings would still take precedence over the former general configurations.