Show *only* docstring in Sphinx documentation?

后端 未结 1 1694
萌比男神i
萌比男神i 2021-01-31 22:18

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

1条回答
  •  不思量自难忘°
    2021-01-31 23:10

    I think what you're looking for is:

    from sphinx.ext import autodoc
    
    class DocsonlyMethodDocumenter(autodoc.MethodDocumenter):
      def format_args(self):
        return None
    
    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.

    0 讨论(0)
提交回复
热议问题