我正在学习python,并更深入地研究super()
类。
在buildin.py
文件中,我看到:
class super(object):
### some code omitted ###
def __init__(self, type1=None, type2=None): # known special case of super.__init__
"""
super() -> same as super(__class__, <first argument>)
super(type) -> unbound super object
super(type, obj) -> bound super object; requires isinstance(obj, type)
super(type, type2) -> bound super object; requires issubclass(type2, type)
Typical use to call a cooperative superclass method:
class C(B):
def meth(self, arg):
super().meth(arg)
This works for class methods too:
class C(B):
@classmethod
def cmeth(cls, arg):
super().cmeth(arg)
# (copied from class doc)
"""
pass
### some code omitted ###
__self__ = property(lambda self: type(object))
"""the instance invoking super(); may be None
:type: type
"""
__thisclass__ = property(lambda self: type(object))
"""the class invoking super()
:type: type
"""
我对property(lambda self: type(object))
的确切功能感到困惑。
我理解lambda
的功能,并且我认为(lambda self: type(object))
总是返回type
而不管self
是什么,因为object
继承自{{ 1}},根据官方文档。