[英]How to override constructor parameters in Sphinx with autodoc?
Let's say I have a class like this:假设我有这样的课程:
class MyClass(object):
""" Summary docs for my class.
Extended documentation for my class.
"""
def __init__(self, *args):
self.values = np.asarray(args)
If I use Sphinx with the autodoc
extension to document this class like so:如果我使用带有autodoc
扩展名的 Sphinx 来记录此类,如下所示:
.. automodule:: mymodule
:members:
...the constructor signature appears as MyClass(*args)
. ...构造函数签名显示为MyClass(*args)
。 I would rather override this and document it as, say, MyClass(first, second, third)
.我宁愿覆盖它并将其记录为MyClass(first, second, third)
。
If this were a function, I could override the signature in the first line of the docstring.如果这是一个函数,我可以覆盖文档字符串第一行中的签名。 But that trick doesn't seem to work on a class docstring.但是这个技巧似乎不适用于类文档字符串。 So how can I override the constructor signature?那么如何覆盖构造函数签名呢?
I think that the best option for you is to do something like this:我认为对你来说最好的选择是做这样的事情:
.. automodule:: mymodule
:members:
:exclude-members: MyClass
.. autoclass:: MyClass(first, second, third)
MyClass
will have params overwritten and other members of mymodule
will be autodocumented. MyClass
将覆盖参数,并且mymodule
的其他成员将被自动记录。 You need to exclude MyClass
using :exclude-members:
because it will be included twice.您需要使用:exclude-members:
排除MyClass
,因为它将被包含两次。 I think it's the simplest solution at the moment.我认为这是目前最简单的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.