我有具有对象属性的 Python 类,这些对象属性仅在运行构造函数时声明,如下所示:
class Foo(object):
def __init__(self, base):
self.basepath = base
temp = []
for run in os.listdir(self.basepath):
if self.foo(run):
temp.append(run)
self.availableruns = tuple(sorted(temp))
如果我现在使用help(Foo)
或尝试Foo
在 Sphinx 中记录,则不会显示self.basepath
andself.availableruns
属性。这对我们 API 的用户来说是个问题。
我尝试寻找一种标准方法来确保解析器可以找到这些“动态声明的”属性(最好是文档字符串),但到目前为止还没有运气。有什么建议么?谢谢。