我有一些相互继承的类。所有类都包含相同的方法(让我们称之为mymethod),由此子类覆盖基类方法。我想mymethod使用sphinx为所有类生成文档。
假设mymethod接受一个论点myargument。此参数对于基方法和继承方法具有相同的类型和含义。为了尽量减少冗余,我myargument只想为基类编写文档,并将文档插入子方法的文档中。也就是说,我不想只对基类进行简单的引用,而是在生成文档时动态插入文本。
这能做到吗?如何?
请在下面找到一些说明问题的代码。
class BaseClass
def mymethod(myargument):
"""This does something
Params
------
myargument : int
Description of the argument
"""
[...]
class MyClass1(BaseClass):
def mymethod(myargument):
"""This does something
Params
------
[here I would like to insert in the description of ``myargument`` from ``BaseClass.mymethod``]
"""
BaseClass.mymethod(myargument)
[...]
class MyClass2(BaseClass):
def mymethod(myargument, argument2):
"""This does something
Params
------
[here I would like to insert in …Run Code Online (Sandbox Code Playgroud) 假设我有一堂课
class A(object):
def myfunction():
"""A."""
pass
Run Code Online (Sandbox Code Playgroud)
和一个子类
class B(A):
def myfunction():
pass
Run Code Online (Sandbox Code Playgroud)
是否可以使用sphinx从A.myfunction继承B.myfunction的API文档?B.myfunction的文档应为"A".同样.