[英]How to refer child class attributes in the parent class docstring?
我正在使用:inherited-members:
來顯示父方法。
在為孩子生成的文檔中,是否可以參考孩子 class?
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 交叉引用語法,以及來自Python 域的適當角色。 之后,您的.rst
中的autodoc 指令會處理 rest。
示例 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:
結果:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.