类与类对象实例的Python文档样式

2024-04-23 09:53:29 发布

您现在位置:Python中文网/ 问答频道 /正文

记录函数参数和类属性类型的标准方法是什么,以区分预期是类实例的函数参数和类属性本身是类对象的类型?在

class TestClass(object):
    def __init__(self):
        pass

class Objectify(object):
    def __init__(self):
        pass    

class NeatDocumentation(object):
    """A class demonstrating neat documentation style.

    Attributes:
        cls (TestClass?): A class you want to test.
        obj (Objectify?): An instance of `Objectify` class.
        string (str): A string because why not.
    """

    def __init__(self, cls_, obj, string):
        self.cls = cls_  # An instance can be created by executing self.cls()
        self.obj = obj
        self.string = string

Tags: selfanobj类型string属性objectinit
1条回答
网友
1楼 · 发布于 2024-04-23 09:53:29

python标准是使用restructedText(http://www.sphinx-doc.org/en/1.4.9/rest.html)的sphinx样式

更准确地说,autodoc模块样式:http://www.sphinx-doc.org/en/1.4.8/ext/autodoc.html

如果你想拥有更漂亮的琴弦,你也可以使用斯芬克斯拿破仑风格: http://www.sphinx-doc.org/en/1.4.9/ext/napoleon.html

在您的情况下,您可以:

:param your_param: Class to test
:type your_param: :class:`Objectify`

或者使用拿破仑:

^{pr2}$

相关问题 更多 >