super() not a panacea?

Michele Simionato michele.simionato at
Wed Feb 18 07:42:42 CET 2004

"Clarence Gardner" <clarence at> wrote in message news:<pan.2004. at>...
> The super object is considered a solution to the "diamond problem". 
> However, a problem comes up if that ultimate base class is also the base
> class for another which inherits from it and another independent base
> class also providing that method.

The solution I see is to introduce a placeholder base class Y 
with a dummy "m" method on top of the hierarchy:

class Y(object):
    def m(self):
class A(Y):
    def m(self):
        super(A, self).m()
        print '   A'

class B(A):
    def m(self):
        super(B, self).m()
        print '   B'

class C(A):
    def m(self):
        super(C, self).m()
        print '   C'

class D(B,C):
    def m(self):
        super(D, self).m()
        print '   D'

class Z(Y):
    def m(self):
        print '   Z'

class X(A, Z):
    def m(self):
        super(X, self).m()
        print '   X'


print X.mro()
print D.mro()

This is the easy solution. If you don't like it, let me know and I
will show you other possibilities.

       Michele Simionato

More information about the Python-list mailing list