super(type, object

    class B1(object):
        def f(self):
            print "B1.f"

    class B2(object):
        def f(self):
            print "B2.f"

    class D(B1, B2):
        pass

    d = D()
    super(B1, d).f()
    print B1.__mro__

Why does the above code print:

B2.f
(<class '__main__.B1'>, <type 'object'>)

whereas the documentation http://docs.python.org/2/library/functions.html#super says:

super(type[, object-or-type]):
... The __mro__ attribute of the type lists the method resolution search order used by ... super(). 

It seems that the MRO, which is used, is not the one of the "type" parameter of super() but the one of the "object-or-type" parameter. Is this an error in the Python documentation?

链接地址: http://www.djcxy.com/p/54792.html

上一篇: 为什么这个多处理代码失败?

下一篇: 超级(类型,对象