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.... 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
<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
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
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
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
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? 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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:
...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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)...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |