属性(lambda self:type(object))在super()函数中有什么作用?

时间:2019-06-20 19:35:34

标签: python lambda super

我正在学习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}},根据官方文档。

0 个答案:

没有答案