【问题标题】:Python DocString (Google Style): How to document class attributes?Python DocString(谷歌风格):如何记录类属性?
【发布时间】:2020-11-11 01:30:17
【问题描述】:

我有这个小例子:

"""Sandbox module"""

class Toto:
    """
    This class is an example

    Attributes:
        class_attribute (str): The class attribute #Unresolved reference
        instance_attribute (str): The instance attribute #OK
    """

    class_attribute = ""

    def __init__(self):
        self.instance_attribute = ""
        pass

这会触发未解决的引用警告 我应该如何正确记录类属性?

【问题讨论】:

    标签: python python-sphinx docstring class-attributes


    【解决方案1】:

    试试这个:

    """
        Sandbox module
        ~~~~~~~~~~~~~~
    """
    
    class Toto:
        """This class is an example
    
        Attributes:
            instance_attribute (str): The instance attribute #OK
        """
        
        #: str: The class attribute #Unresolved reference
        class_attribute = ""
    
        def __init__(self):
            self.instance_attribute = ""
            pass
    

    这对我使用 sphinx 很有效。

    【讨论】:

      猜你喜欢
      • 2011-07-22
      • 2011-03-04
      • 2020-07-02
      • 1970-01-01
      • 1970-01-01
      • 2012-10-05
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      相关资源
      最近更新 更多