FEEDBACK WANTED: Type/class unification
Duncan Booth
duncan at NOSPAMrcp.co.uk
Tue Jul 31 04:07:25 EDT 2001
Guido van Rossum <guido at python.org> wrote in news:cp66cd12yp.fsf at cj20424-
a.reston1.va.home.com:
> Any questions, don't hesitate to ask.
I have a question, or perhaps an observation about the new rules for
resolving diamond inheritance.
Given a class hierarchy such as:
class A: pass
class B(A):
def save(self): pass
class C(A):
def save(self): pass
class D(B, C):
def foo(self):
self.save() # Calls B.save
Now, if I add the following code:
class E(B): pass
class F(D, E): pass
f = F()
f.foo()
My understanding of the new rules is that calling f.foo() will result in a
call to C.save instead of B.save (or in other words, any class that depends
on the search order for base classes may find this order mysteriously
changing if it itself is subclassed).
Is my understanding correct? Does it matter? Something similar already
happens in existing Python programs (define class F(C, D) and you get the
same effect), but previously you were less likely to encounter diamond
inheritance.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list