在autodoc中排除模块docstring

Jon*_*tan 6 python python-sphinx

我试图在Sphinx中使用autodoc打印出特定模块中每个函数的文档字符串,但不包括模块的文档字符串。可能吗?

原因是我使用模块docstring指定命令行选项(带有可爱的docopt)。

mzj*_*zjn 6

将以下内容添加到conf.py

def remove_module_docstring(app, what, name, obj, options, lines):
    if what == "module" and name == "yourmodule":
        del lines[:]

def setup(app):
    app.connect("autodoc-process-docstring", remove_module_docstring)
Run Code Online (Sandbox Code Playgroud)

此代码yourmodule通过为autodoc-process-docstring事件提供处理程序来删除模块中的模块docstring