MRO inconsistency: why?

Ravi ra.ravi.rav at gmail.com
Wed Oct 8 21:09:12 CEST 2008


Why the following code gives inconsistent method resolution order
error:

class X(object):
        x = 4
        def f(self):
                print 'f in X'
                print dir(X)
                X.g(self)
        def g(self):
                print 'g in X'

class Y(object, X):
        def g(self):
                print 'g in Y'

o = Y()
o.f()

While this code doesn't:

class X(object):
        x = 4
        def f(self):
                print 'f in X'
                print dir(X)
                X.g(self)
        def g(self):
                print 'g in X'

class Y(X, object):
        def g(self):
                print 'g in Y'

o = Y()
o.f()



More information about the Python-list mailing list