我试图使用Sphinx来记录我的Python类。我使用autodoc:
.. autoclass:: Bus
:members:
虽然它正确地获取了我的方法的docstring,但是那些被修饰的方法:
@checkStale
def open(self):
"""
Some docs.
"""
# Code
有@checkStale
存在
def checkStale(f):
@wraps(f)
def newf(self, *args, **kwargs):
if self._stale:
raise Exception
return f(self, *args, **kwargs)
return newf
原型不正确,例如open(*args, **kwargs)
。
我该怎么解决?我的印象是使用@wraps
可以解决这类问题。
我对芹菜@task decorator也有同样的问题。
您还可以通过向rst文件中添加正确的函数签名来解决此问题,如下所示:
它仍然会自动记录非decorator成员。
sphinx文档在http://www.sphinx-doc.org/en/master/ext/autodoc.html#directive-automodule中提到了这一点——搜索“如果方法的签名被装饰器隐藏,则此选项非常有用。”
在我的例子中,我必须使用autofunction在django应用程序的tasks.py模块中指定芹菜任务的签名:
要展开我的评论:
正如您在评论中所问的,decorator包不是标准库的一部分。
您可以使用如下代码(未经测试):
添加到版本1.1中,现在可以通过在docstring的第一行提供自定义值来重写方法签名。
http://sphinx-doc.org/ext/autodoc.html#confval-autodoc_docstring_signature
相关问题 更多 >
编程相关推荐