multiple inheritance of a dynamic list of classes?

Neil Cerutti horpner at yahoo.com
Wed Feb 14 14:22:03 EST 2007


On 2007-02-14, Peter Otten <__peter__ at web.de> wrote:
> Neil Cerutti wrote:
>
>> On 2007-02-13, Peter Otten <__peter__ at web.de> wrote:
>>> Well, what problems ocurring with
>>>
>>> class A: pass
>>> class B: pass
>>> class C(A, B): pass
>>>
>>> could be avoided by writing
>>>
>>> class A: pass
>>> class B(A): pass
>>> class C(B): pass
>>>
>>> instead?
>> 
>> With multiple inheritance, the choice of algorithm for Method
>> Resolution Ordering isn't obvious or trivial. As I understand it,
>> Python got it wrong for quite some time, allowing "bad"
>> hierarchies to compile, i.e., classes for which the properties of
>> local precedence ordering and monotonicity did not hold.
>> 
>> URL:http://www.python.org/download/releases/2.3/mro/
>
> Is it correct that as long as no classes occur twice in the
> hierarchy no such ambiguities can arise?

As long as you forbid the diamond-shaped hierarchy, I think so.
Of course, since all new-style classes inherit from 'object' you
can't avoid it in practice, and a good algorithm for MRO had to
be stolen from Dylan. ;)

-- 
Neil Cerutti



More information about the Python-list mailing list