【发布时间】:2017-06-23 15:23:29
【问题描述】:
当我有一个带有这样定义的闭包的装饰器时:
def Decorator(arg):
class InnerDecorator:
"""Here i use the arg: {arg}"""
__doc__ = __doc__.format(arg=arg)
def __init__(self, func):
self.func = func
# make arg an instance attribute
self.arg = arg
def __call__(self):
return self.func()
return InnerDecorator
我是这样使用的:
class MyClass(object):
@Decorator("ARG")
def foo(self):
pass
@Decorator("Other ARG")
def bar(self):
pass
我可以使用交互式外壳查看“foo”和“bar”的正确文档字符串:
>>> help(MyClass)
我的问题是: 有没有办法用 sphinx 为方法 'foo' 和 'bar' 生成自动文档? 我试过了,
.. autoclass:: MyClass
:members:
但这不起作用。
谢谢
【问题讨论】:
标签: python python-sphinx python-decorators