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

noreply@sourceforge.net noreply@sourceforge.net
Fri, 22 Mar 2002 19:48:56 -0800


Bugs item #481985, was opened at 2001-11-15 01: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: Closed
>Resolution: Wont Fix
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.
"""

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

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-03-22 22:48

Message:
Logged In: YES 
user_id=6380

Closing as Won't Fix. In the light of conflicts, the MRO
algorithm can yield surprises, yes. Then don't do that.

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

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