如何标准地记录函数参数和类属性的类型,以区分那些预期是类实例和那些预期是类对象本身?
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
:py:class:
,但这并不能回答问题,因为 OP 正在寻找“rtype”风格的语法(即类型提示)。 - Thiago Figueirortype
。他正在寻找类 'type' 的等效项:py:class
,而不是实例类型。 - stelios