mixins and new style classes

M

mk

class Person(object):
.... pass
........ def hello(self):
.... print 'hello'
....Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Cannot create a consistent method resolution
order (MRO) for bases object, Friendly




But it works for old-style classes:

.... pass
........ def hello(self):
.... print 'hello'
....hello


Python is 2.6.1.
 
B

Bruno Desthuilliers

mk a écrit :
... pass
...
... def hello(self):
... print 'hello'
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Cannot create a consistent method resolution
order (MRO) for bases object, Friendly

Indeed. After the addition of Friendly to Person.__bases__, the mro for
Person would be (Person, object, Friendly). But the mro for Friendly is
(Friendly, object). This is not consistent. The right solution would be
to inject Friendly before object, ie:

Person.__bases__ = (Mixin, object)

Now the bad news is that this fails too:

TypeError: __bases__ assignment: 'Mixin' deallocator differs from 'object'

The above problem is not new, and had been discussed here:

http://bugs.python.org/issue672115

....and it's still unresolved AFAICT :-/

OTHO, the concrete use case for such a feature seem to be rather uncommon.
But it works for old-style classes:

Old-style classes are a very different beast.
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top