类与类对象实例的Python文档样式
记录函数参数和类属性类型的标准方法是什么,以区分预期为类实例的参数和预期为类对象本身的参数类与类对象实例的Python文档样式,python,documentation,docstring,Python,Documentation,Docstring,记录函数参数和类属性类型的标准方法是什么,以区分预期为类实例的参数和预期为类对象本身的参数 class TestClass(object): def __init__(self): pass class Objectify(object): def __init__(self): pass class NeatDocumentation(object): """A class demonstrating neat documen
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
python标准是sphinx样式,它使用StructuredText() 更准确地说,autodoc模块样式: 如果您想拥有更漂亮的琴弦,还可以使用斯芬克斯-拿破仑风格: 在您的情况下,您可以:
:param your_param: Class to test
:type your_param: :class:`Objectify`
或者使用拿破仑:
Args:
your_param (Objectify): The :class:`Objectify` class to test
正确的语法是
:py:class:
,但这并不能回答问题,因为OP正在寻找“rtype”样式的语法(即类型暗示),他也没有在寻找rtype
。他正在寻找类“类型”的等价物:py:class
,而不是实例类型。现在回答404。