簡體   English   中英

獅身人面像中的方法組的文檔字符串

[英]Docstring for groups of methods in sphinx

是否可以在Sphinx生成的文檔中為方法組添加文檔字符串?

例如,我想要類似的東西:

class MyClass():
    """Doc of the class"""
    def __init__(self):
        pass

    """----- The following part is about imports -----"""

    def import_from_source_1(self):
        """Doc of import_from_source_1"""
        pass

    def import_from_source_2(self):
        """Doc of import_from_source_2"""
        pass

    """----- The following part is about exports-----"""

    def export_to_dest_1(self):
        """Doc of export_to_dest_1"""
        pass

    def export_to_dest_2(self):
        """Doc of export_to_dest_2"""
        pass

預期的輸出將是:

MyClass
    Doc of the class

----- The following part is about imports -----
import_from_source_1
    Doc of import_from_source_1

import_from_source_2
    Doc of import_from_source_2

----- The following part is about exports-----
export_to_dest_1
    Doc of export_to_dest_1

export_to_dest_2
    Doc of export_to_dest_2

請注意,我的目標不是(僅)將方法分組(如在sphinx中的“ 分組方法”文檔字符串中找到的),而是將文檔字符串添加到組中。

docstring是一個字符串文字,它作為模塊,函數,類或方法定義( https://python.org/dev/peps/pep-0257/#id15 )中的第一條語句出現。 您不能像問題中那樣具有“額外”的文檔字符串。

但是,您可以使用automethod進行分組:

.. currentmodule:: mymodule

.. autoclass:: MyClass

   The following part is about imports

   .. automethod:: import_from_source_1
   .. automethod:: import_from_source_2

   The following part is about exports

   .. automethod:: export_to_dest_1
   .. automethod:: export_to_dest_2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM