multiple inheritance with builtins
Giovanni Bajo
noway at sorry.com
Sat Mar 5 22:03:11 EST 2005
Hello,
I noticed that bultin types like list, set, dict, tuple don't seem to adhere to
the convention of using super() in constructor to correctly allow
diamond-shaped inheritance (through MRO). For instance:
>>> class A(object):
... def __init__(self):
... print "A.__init__"
... super(A, self).__init__()
...
>>> class B(A, list):
... def __init__(self):
... print "B.__init__"
... super(B, self).__init__()
...
>>> B.__mro__
(<class '__main__.B'>, <class '__main__.A'>, <type 'list'>, <type 'object'>)
>>> B()
B.__init__
A.__init__
[]
>>> class C(list, A):
... def __init__(self):
... print "C.__init__"
... super(C, self).__init__()
...
>>> C.__mro__
(<class '__main__.C'>, <type 'list'>, <class '__main__.A'>, <type 'object'>)
>>> C()
C.__init__
[]
It seems weird to me that I have to swap the order of bases to get the expected
behaviour. Is there a reason for this, or is it simply a bug that should be
fixed?
--
Giovanni Bajo
More information about the Python-list
mailing list