[Python-bugs-list] [ python-Bugs-481985 ] Uncaught MI order conflict

noreply@sourceforge.net noreply@sourceforge.net
Wed, 14 Nov 2001 22:29:37 -0800


Bugs item #481985, was opened at 2001-11-14 22:29
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=481985&group_id=5470

Category: Type/class unification
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Tim Peters (tim_one)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Uncaught MI order conflict

Initial Comment:
Dubious MRO from mixing classic and new-style classes 
in multiple inheritance:

> def mrolist(k):
>     return ' '.join([c.__name__ for c in k.__mro__])
> 
> def f():
>     # No question here.
>     class C: pass
>     class M1(C, object): pass
>     print mrolist(M1) # "M1 C object"
> 
>     # And no question here.
>     class D(C): pass
>     class M2(object, D): pass
>     print mrolist(M2) # "M2 object D C"
> 
>     # Here I expected
>     #     "M3 M1 M2 object D C"
>     # but got
>     #     "M3 M1 M2 D C object"
>     class M3(M1, M2): pass
>     print mrolist(M3)
> 
> f()

"""
If I add

    class M4(M2, M1): pass
    print mrolist(M4)

this prints what you may have expected:

    M4 M2 M1 object D C

My conclusion is that it's an artefact of how 
conservative_merge() resolves the conflict between M1 
and M2: in M1, C preceeds object, while in M2, object 
preceeds C.  This order conflict is supposed to be
outlawed, but I didn't feel like testing for it -- the 
function serious_order_disagreements() always returns 
false.

In the light of conflicts, the algorithm in 
conservative() apparently favors the order of the 
first base class encountered.
"""

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=481985&group_id=5470