473,507 Members | 8,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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....

Jun 26 '06 #1
8 6889
di*************@gmail.com wrote:
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....


Yes, do that.

That's an amazing error.

~Simon

Jun 26 '06 #2

<di*************@gmail.com> wrote in message
news:11**********************@y41g2000cwy.googlegr oups.com...
What are the reason one would get this error: TypeError: Cannot create
a consistent method resolution order (MRO) for bases object ??
Because the interpreter cannot ;-)
I can provide the code if needed....


Details beget details ;-)
Yes, the class statement (header line up to ':') that bombed and the same
(first line) for classes it inherits from (and their base classes). The
conflict should be in the latter.

tjr

Jun 26 '06 #3
Hint: If I change Dog and Bat to old-style classes, there's no problem,
everything works fine.
Okay, here's the code dump from my playground::
------------------------------------------
#!/usr/bin/env python

class Mixin:
def mixin(object, *classes):
NewClass = type('Mixin', (object.__class__,) + classes, {})
newobj = NewClass()
newobj.__dict__.update(object.__dict__)
return newobj

class Cat(object):
def __init__(self):
self.love = 0
def meow(self):
print "meow"
class Dog(object):
def bark(self):
print "bark"
class Bat(object):
def scream(self):
print "scream"

mycat = Cat()
mycat.love = 4
mycat.__class__.__bases__ += (Mixin,)
mycat.mixin(Dog, Bat)
print mycat.love

def isClass(object):
if isinstance(object, type):
return True
elif isinstance(object, types.ClassType):
return True
else:
return False

def listClasses():
classes = []
for eachobj in globals().keys():
if isClass(globals()[eachobj]):
classes.append(globals()[eachobj])
print eachobj
return classes

def applyMixinGlobal(*Mixins):
for eachclass in listClasses():
MixInto(eachclass, Mixins)
#applyMixinGlobal(Mixin)

def MixInto(Class, *Mixins):
for eachMixin in Mixins:
if eachMixin not in Class.__bases__:
Class.__bases__ += (eachMixin,)
MixInto(Bat, Mixin)
Bat.__bases__ += (Dog,)
dargo = Bat()
dargo = dargo.mixin(Cat)
dargo.meow()

Simon Forman wrote:
di*************@gmail.com wrote:
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....


Yes, do that.

That's an amazing error.

~Simon


Jun 26 '06 #4
Oh, I forgot the line that bombed, sorry:

line 52, in __main__
Bat.__bases__ += (Dog,)
TypeError: Cannot create a consistent method resolution
order (MRO) for bases object, Mixin, Dog

See my other post for the complete code and my relevant note about
new-style classes, thanks...

Terry Reedy wrote:
<di*************@gmail.com> wrote in message
news:11**********************@y41g2000cwy.googlegr oups.com...
What are the reason one would get this error: TypeError: Cannot create
a consistent method resolution order (MRO) for bases object ??


Because the interpreter cannot ;-)
I can provide the code if needed....


Details beget details ;-)
Yes, the class statement (header line up to ':') that bombed and the same
(first line) for classes it inherits from (and their base classes). The
conflict should be in the latter.

tjr


Jun 26 '06 #5
Le lundi 26 juin 2006 20:06, di*************@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
Jun 27 '06 #6

Maric Michaud wrote:
Le lundi 26 juin 2006 20:06, di*************@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 inconsistencyin
this path, for example duplicate the type object before another type (or any
type wich appear to be the ancestor of another).

--


Ah, thank you Maric, I see the problem. I diagrammed the flow of class
inheritance and I can see the problem clearly. Ruby doesn't have this
problem because it uses a single inheritance model complemented by the
power of mixins (modules of functionality mixed into classes as
needed). So what's the Pythonic solution to this problem?

Jun 27 '06 #7
di*************@gmail.com wrote:
Maric Michaud wrote:
Le lundi 26 juin 2006 20:06, di*************@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).

--

Ah, thank you Maric, I see the problem. I diagrammed the flow of class
inheritance and I can see the problem clearly. Ruby doesn't have this
problem because it uses a single inheritance model complemented by the
power of mixins (modules of functionality mixed into classes as
needed). So what's the Pythonic solution to this problem?

Technically, wait until Python 3.0. Until then, just make sure all your
classes inherit from (something that inherits from ...) object.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Jun 27 '06 #8
di*************@gmail.com wrote:
What are the reason one would get this error: TypeError: Cannot create
a consistent method resolution order (MRO) for bases object ??


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

Michele Simionato

Jun 27 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3630
by: Sam Commar | last post by:
We are using a Standard Microsoft Product called Solomon which has a Web interface. We have installed this in more than 50 sites but we are getting the following error after being in the Web...
3
5180
by: Pat | last post by:
A97, WinXP Hello, I am looking for a way to create a task (in the windows task scheduler) from an Access MDB using VBA. I found this great DLL: ...
1
7662
by: Zhou Jingxiong | last post by:
Hi I am using third party COM component which come with an installation program (.exe file included). The program will be register to registry automatically upon installation. There is no...
2
5528
by: W. Broersen | last post by:
I want to use Outlook.Application, but I donot get further. Dim objOLApp As Outlook.Application objOLApp = CreateObject("Outlook.Application") Everytime I'll get the following error: Cannot...
1
15540
by: Rocio | last post by:
I have a windows app. written in VB6, now we need to expose some of its classes through a web service. I am only able to expose the classes using late binding becasue that's the way the original...
3
4004
by: Allan Ebdrup | last post by:
I get the error "Error creating control: ID property is not specified" when I view my custom web control in design view. I add the control that gives an error in OnInit like this: ----- foreach...
1
5359
by: Allan Ebdrup | last post by:
I get the error: "Cannot create an object of type 'CustomWizard' from its string representation 'CustomWizard1' for the CustomWizard Property." when I view my custom server web control in...
5
6767
by: Marc Oldenhof | last post by:
Hello all, I'm pretty new to Python, but use it a lot lately. I'm getting a crazy error trying to do operations on a string list after importing numpy. Minimal example: Python 2.5.1...
2
1587
by: nandhu678 | last post by:
for district in query: self.response.out.write('<tr><td bgcolor="#ffffff" style="font-family:arial;font-size:12px">') self.response.out.write(district.Dis_Id)...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.