Skip to content Skip to sidebar Skip to footer

Show *only* Docstring In Sphinx Documentation?

Sphinx has a feature called automethod that extracts the documentation from a method's docstring and embeds that into the documentation. But it not only embeds the docstring, but a

Solution 1:

I think what you're looking for is:

from sphinx.ext import autodoc

classDocsonlyMethodDocumenter(autodoc.MethodDocumenter):
  defformat_args(self):
    returnNone

autodoc.add_documenter(DocsonlyMethodDocumenter)

per the current sources this should allow overriding what class is responsible for documenting methods (older versions of add_documenter forbade such overrides, but now they're explicitly allowed). Having format_args return None, of course, is THE documented way in autodoc to say "don't bother with the signature".

I think this is the clean, architected way to perform this task, and, as such, preferable to monkeypatching alternatives. If you need to live with some old versions of sphinx however you may indeed have to monkeypatch (autodoc.MethodDocumenter.format_args=lambda _:None -- eek!-) though I would recommend upgrading sphinx to the current version as a better approach if at all feasible in your specific deployment.

Post a Comment for "Show *only* Docstring In Sphinx Documentation?"