Python 如何将decorator参数注入docstring?
我在API中使用了一个特定的装饰器模式,它看起来像这样(简化): 我正在使用斯芬克斯生成我的文档。我想将decorator的参数注入到它所修饰的函数的docstring中。对于上面的示例,我希望文档如下所示:Python 如何将decorator参数注入docstring?,python,python-sphinx,python-decorators,docstring,Python,Python Sphinx,Python Decorators,Docstring,我在API中使用了一个特定的装饰器模式,它看起来像这样(简化): 我正在使用斯芬克斯生成我的文档。我想将decorator的参数注入到它所修饰的函数的docstring中。对于上面的示例,我希望文档如下所示: mypackage.something module mypackage.something.double(x) This endpoint doubles the number you give it. Attributes: pat
mypackage.something module
mypackage.something.double(x)
This endpoint doubles the number you give it.
Attributes:
path: /double
method: GET
Args:
x: (int) the number you want to double
Returns:
x_double: (int) x * 2
我怎样才能做到这一点?我正在考虑编写一个脚本,将这些内容注入到生成的文档中,但我想知道是否有更简单的方法
另外,是的,装饰程序正在使用
functools.wrapps
这里的棘手部分是在描述和参数之间插入属性。但是装饰程序不能从输入
和输出
参数中生成参数
和`返回
部分吗?然后您可以简单地将生成的字符串附加到double.\uu doc\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
@chepner我知道你指的是什么,这应该行得通!这里棘手的部分是在描述和参数之间插入属性。但是装饰程序不能从输入
和输出
参数中生成参数
和`返回
部分吗?然后您可以简单地将生成的字符串附加到double.\uu doc\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
@chepner我知道你指的是什么,这应该行得通!
mypackage.something module
mypackage.something.double(x)
This endpoint doubles the number you give it.
Attributes:
path: /double
method: GET
Args:
x: (int) the number you want to double
Returns:
x_double: (int) x * 2