This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Method resolution order in Py 2.2 - 2.3
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: alex_nanou, nascheme
Priority: normal Keywords:

Created on 2002-08-23 23:00 by alex_nanou, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug.py alex_nanou, 2002-08-23 23:17 The indented version of what is in the original report text.
Messages (2)
msg12149 - (view) Author: Alex A. Naanou (alex_nanou) Date: 2002-08-23 23:00
-- 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!!
msg12150 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2002-08-23 23:30
Logged In: YES 
user_id=35752

You need to make 'A' subclass from 'object' in order to get
the new
MRO behavior.
History
Date User Action Args
2022-04-10 16:05:37adminsetgithub: 37081
2002-08-23 23:00:48alex_nanoucreate