我正在使用:inherited-members:
显示父方法。
在为子级生成的文档中,是否可以引用子级?
class Parent:
"""This is a {Child class name} class
This is in the {Child group attribute} group
"""
group = ''
...
class Child(Parent):
group = 'TheChild'
...
在为孩子生成的文档中,我想看到:
> class Child(Parent)
> Bases: Parent
> This is a Child class.
> It is in the TheChild group
狮身人面像可能吗?
您可以在文档字符串中使用Sphinx Cross-referencing syntax,并从roles中使用适当的Python domain。之后,autodoc directives中的.rst
会处理其余的工作。
示例parent_child.py
class Parent:
"""
This is a :py:class:`Child` class.
This is in the :py:data:`Child.group` attribute.
"""
group = 'TheParent'
class Child(Parent):
group = 'TheChild'
parent_child.rst
Parent\_Child
=============
.. autoclass:: parent_child.Parent
:members:
:undoc-members:
:show-inheritance:
.. autoclass:: parent_child.Child
:members:
:undoc-members:
:show-inheritance:
结果: