[Python-bugs-list] [ python-Bugs-599452 ] Method resolution order in Py 2.2 - 2.3
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 23 Aug 2002 16:30:21 -0700
Bugs item #599452, was opened at 2002-08-23 23:00
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=599452&group_id=5470
Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Alex A. Naanou (alex_nanou)
Assigned to: Nobody/Anonymous (nobody)
Summary: Method resolution order in Py 2.2 - 2.3
Initial Comment:
-- from "What's new in Python 2.2"
section 2.3 "Multiple Inheritance: The Diamond Rule"
"""
Multiple inheritance has also been made more useful
through changing the rules under which names are
resolved.
"""
Well, for a feature that was officially "introduced" in
version 2.2 it shows a remarkable lack of presence
(even in the CVS versions of 2.3)!!
// though, I could have missed something (an elephant in
// my backyard!), if so please point it out...
Description:
Actually, there is nothing wrong... the function in
question is just not changed since version 2.1.x, thus
we get the old style lookup table (Method resolution
order).
I'll try not to get too carried away.. here is an
example 'almost' literally taken from that same section
of the documentation mentioned above:
---cut---
class A:
def save(self):
return "I am 'A.save'"
class B(A):
pass
class C(A):
def save(self):
return "I am 'C.save'"
class D(B,C):
pass
print D().save()
---uncut---
Expected Results:
something printed EXACTLY like:
>>> I am 'C.save'
Actual Result:
//here is the part where I faint... :|
we get:
>>> I am 'A.save'
The results are identical for:
- Python 2.2
- Python 2.2.1
- Python 2.3 (CVS)
Thanks!!
----------------------------------------------------------------------
>Comment By: Neil Schemenauer (nascheme)
Date: 2002-08-23 23:30
Message:
Logged In: YES
user_id=35752
You need to make 'A' subclass from 'object' in order to get
the new
MRO behavior.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=599452&group_id=5470