Multiple inheritance : waht does this error mean ?

J

jnair

I am using Python 2.4.3
...: pass
...:
------------------------------------------------------------
Traceback (most recent call last):
File "<console>", line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases object, list


Regards
Jitendra Nair
 
B

Ben Finney

...: pass
...:
------------------------------------------------------------
Traceback (most recent call last):
File "<console>", line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases object, list

The class 'object' is already the base class of 'list', and of every
other basic type.

Python is saying that you need to decide what you want; inheritance
from 'object', or inheritance from something that already inherits
from 'object'.
 
J

John Machin

Question for you: what do you think that "class K(object,list):"
means?? What are you trying to achieve? What do you plan to do with K?
If you want it to be a subclass of list, all you have to do is "class
K(list):".
 
P

Peter Otten

I am using Python 2.4.3

...: pass
...:
------------------------------------------------------------
Traceback (most recent call last):
File "<console>", line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases object, list

class K(object, list): pass

specifies that a method should be looked up first in object, then in list.
As list inherits from object, its method resolution order
(<type 'list'>, <type 'object'>)

specifies that a method should be looked up first in list, then in object.
Python refuses to resolve the conflict for you, but you can do it manually:
(<class '__main__.K2'>, <type 'list'>, <type 'object'>)

Now K2, list, and object can agree to look for a method in K2, then list,
then object. However, you get the same effect by just inheriting from list:
(<class '__main__.K3'>, <type 'list'>, <type 'object'>)

Peter
 
M

Michele Simionato

I am using Python 2.4.3

...: pass
...:
------------------------------------------------------------
Traceback (most recent call last):
File "<console>", line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases object, list

It is explained here:

http://www.python.org/download/releases/2.3/mro/

Michele Simionato
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top