Is it possible to override Sphinx autodoc for specific functions?

佐手、 提交于 2019-12-17 19:15:47

问题


I'm using Sphinx's autodoc plugin to automatically document a set of modules. I have a function that accepts *args, and I'd like to override the documentation to show the slightly nicer funcname(arg1[, arg2[, ...]]) style that the Python stdlib docs use.

Is it possible to override the autodoc output for a specific function?


回答1:


It is possible to override a signature by using autofunction:

.. automodule:: yourmodule
   :members:
   :exclude-members: funcname

.. autofunction:: funcname(arg1[, arg2[, ...]])

However, the function with the overridden signature is not sorted with the other functions pulled in with automodule. Using explicit autofunction directives for every function works around that:

.. autofunction:: firstfunc

.. autofunction:: funcname(arg1[, arg2[, ...]])

.. autofunction:: thirdfunc

Addition

You can also append to the docstring:

.. autofunction:: funcname(arg1[, arg2[, ...]])

   Extra documentation here.  

To override both signature and docstring, use function instead of autofunction.

Addition 2

The signature can also be overridden by having a signature as the first line of the function docstring. See this answer for details.



来源:https://stackoverflow.com/questions/5365684/is-it-possible-to-override-sphinx-autodoc-for-specific-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!