MRO inconsistency: why?

Christian Heimes lists at cheimes.de
Wed Oct 8 15:28:29 EDT 2008


Ravi wrote:
> Why the following code gives inconsistent method resolution order
> error:
[...]

Your problem can be reduced to:

 >>> class A(object):
...     pass
...
 >>> A.__mro__
(<class '__main__.A'>, <type 'object'>)
 >>> class B(object, A):
...     pass
...
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
     Cannot create a consistent method resolution
order (MRO) for bases object, A
 >>> class C(A, object):
...     pass
...
 >>> C.__mro__
(<class '__main__.C'>, <class '__main__.A'>, <type 'object'>)

The class B would require a MRO of (<class '__main__.B'>, <type 
'object'>, <class '__main__.A'>, <type 'object'>) which isn't allowed in 
Python.

Christian




More information about the Python-list mailing list