TypeError: Cannot create a consistent method resolution order (MRO) for bases object

Maric Michaud maric at aristote.info
Tue Jun 27 02:54:32 CEST 2006


Le lundi 26 juin 2006 20:06, digitalorganics at gmail.com a écrit :
> What are the reason one would get this error: TypeError: Cannot create
> a consistent method resolution order (MRO) for bases object ??
>
> I can provide the code if needed....
This is the python solution to the diamond problem (cf. wikipedia).

In [61]: class a(object) : pass
   ....:
In [62]: class b(a) : pass
   ....:
In [63]: class c(object, a) : pass
   ....:
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most recent 
call last)

/home/maric/<ipython console>

TypeError: Error when calling the metaclass bases
    Cannot create a consistent method resolution
order (MRO) for bases object, a

In [64]: b.mro()
Out[64]: [<class '__main__.b'>, <class '__main__.a'>, <type 'object'>]

In [65]: class c(a, object) : pass
   ....:

In [66]: c.mro()
Out[66]: [<class '__main__.c'>, <class '__main__.a'>, <type 'object'>]

In [67]: class d(b, c) : pass
   ....:

In [69]: d.mro()
Out[69]:
[<class '__main__.d'>,
 <class '__main__.b'>,
 <class '__main__.c'>,
 <class '__main__.a'>,
 <type 'object'>]

mro means "method resolution order", this is the path the interpreter will 
look for attributes for a given class. You cannot introduce inconsistency in 
this path, for example duplicate the type object before another type (or any 
type wich appear to be the ancestor of another).

-- 
_____________

Maric Michaud
_____________

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097



More information about the Python-list mailing list