我正在将sphinx文档添加到几个项目中,但我担心未来的开发人员在方法界面更改时不会严格更新文档。有没有办法让sphinx根据方法定义中实际指定的内容验证所描述的参数列表?
例如,让我们说我使用sphinx-quickstart设置了sphinx,添加了autodoc,并尝试构建以下"模块":
def product(arg_one, arg_two):
'''
:param arg_one: an object to be multiplied by arg_two
:type arg_one: Object
:param arg_two: an integer which defines the number of arg_one to return
:type arg_two: integer
:returns: The product of arg_one and arg_two
:raises: TypeError
'''
return arg_one * arg_two
而且,从现在起一周后,Bob Doe更新产品如下:
def product(value, number, catch_errors=False):
'''
:param arg_one: an object to be multiplied by arg_two
:type arg_one: Object
:param arg_two: an integer which defines the number of arg_one to return
:type arg_two: integer
:returns: The product of arg_one and arg_two
:raises: TypeError
'''
try:
return value * number
except TypeError as exc:
if catch_errors:
return None
raise
现在,sphinx文档并不正确 - 它缺少新的catch_errors字段,并且变量已经重命名。但是,运行
sphinx-build . ./_build
第二次没有发现问题 - 它只是报告
Running Sphinx v1.6.5
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
no targets are out of date.
build succeeded.
我希望(或希望)Sphinx能够根据方法的实际代码验证文档字符串,并且在文档和实现不在 - 时失败(或至少以某种方式表明)同步。
如果狮身人面像不具备这个能力,那还有其他选择吗?我知道那里function annotations in Python 3,但我们目前支持Python 2和Python 3,所以这不是一个选项。