如何用狮身人面像自动对接装饰方法? [英] How to autodoc decorated methods with sphinx?
本文介绍了如何用狮身人面像自动对接装饰方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我有一个具有如下定义的闭包的装饰符时:
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)
我的问题是: 有没有办法用狮身人面像为方法‘foo’和‘bar’生成自动对接? 我试过了,
.. autoclass:: MyClass
:members:
但这不起作用。
目前为止的Thx
推荐答案
此答案帮助我使其正常工作:https://stackoverflow.com/a/15693082/1901330
作为我的示例代码的答案,我执行以下操作:
.. autoclass:: module.MyClass
.. automethod:: module.MyClass.foo(self)
.. automethod:: module.MyClass.bar(self)
这篇关于如何用狮身人面像自动对接装饰方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文