sphinx.ext.autodoc: Keeping names of constants in signature

后端 未结 2 1863
Happy的楠姐
Happy的楠姐 2020-12-16 03:51

I\'m using Sphinx\'s autodoc feature to document my API.

Example:

DEFAULT_OPTION = \'default\'
def do_something(msg, option=DEFAULT_OPTION):
    pri         


        
2条回答
  •  长情又很酷
    2020-12-16 04:15

    You probably have to override the signature by hand in the reST file.

    It's hard to come up with a better answer. Autodoc imports the modules it documents, so all module-level code (including default function arguments) is executed.

    See also these similar questions: here and here.


    Update:

    I just realized that there is another option. You can override the signature by including it as the very first line of the docstring. See the documentation of the autodoc_docstring_signature configuration variable, and this answer.

提交回复
热议问题