Python 当我尝试使用super(type,obj)创建绑定类方法时,有一些不同的地方

Python 当我尝试使用super(type,obj)创建绑定类方法时,有一些不同的地方,python,super,Python,Super,我输入了这样的代码 class A: @classmethod def m1(cls): pass class B(A): @classmethod def m1(cls): print(super(B, B).m1) class A(object): def __new__(cls): print(super(A, A).__new__) 然后我调用了B.m1,结果是 <bound method

我输入了这样的代码

class A:
    @classmethod
    def m1(cls):
        pass

class B(A):
    @classmethod
    def m1(cls):
        print(super(B, B).m1)
class A(object):
    def __new__(cls):
        print(super(A, A).__new__)
然后我调用了B.m1,结果是

<bound method A.m1 of <class '__main__.B'>>
<method-wrapper '__init__' of A object at 0x104f59da0>
我原以为它会和前一个一样。但结果让我困惑:

<built-in method __new__ of type object at 0x103e33cf0>
结果是

<bound method A.m1 of <class '__main__.B'>>
<method-wrapper '__init__' of A object at 0x104f59da0>
结果是

<bound method A.m1 of <__main__.B object at 0x104f59da0>>


所以我想知道为什么内置对象和自定义对象的结果不同?

命名。没别的了。您处理的是C代码中定义的方法(描述符),而不是Python代码中定义的方法


没有功能上的差异,实际上不需要担心什么是实现上的差异。

命名。没别的了。您处理的是C代码中定义的方法(描述符),而不是Python代码中定义的方法


没有功能上的差异,真的不需要担心实现上的差异。

我发现,如果我尝试使用super(B,B).m1()而不将cls传递给m1,它会工作,但是如果我尝试使用super(A,A)。\uuuuuuu new\uuuuuu(),它不工作,我必须使用super(A,A)。\uuu new\uuuuuuuu(A)或只是super().@user9010294:
\uuuuu new\uuuuu
被视为类方法,但实际上并不是这样绑定的。相反,它是一个静态方法,您需要手动传入该类。我明白了。感谢您的帮助我发现,如果我尝试使用super(B,B).m1()而不将cls传递给m1,它是有效的,但如果我尝试使用super(A,A)。\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu(),它不起作用,我必须使用super(A,A)。\uuuuuuuuu。相反,它是一个静态方法,您需要手动传入该类。我明白了。感谢您的帮助注意:
\uuuu new\uuu
是一个静态方法,而不是类方法。请参阅:
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。请参阅:
\uuuuu new\uuuuuu()
是一个静态方法(特殊情况下,您无需将其声明为静态方法)