[issue5229] Documentation for super() neglects to say what super() actually does
Daniel Stutzbach
report at bugs.python.org
Thu Feb 26 00:33:40 CET 2009
Daniel Stutzbach <daniel at stutzbachenterprises.com> added the comment:
Actually, it's essential to how super() works. Here's an example using
single inheritance:
class A(object):
def foo(self):
print 'A'
class B(object):
def foo(self):
super(B, self).foo()
print 'B'
class C(object):
def foo(self):
super(C, self).foo()
print 'C'
x = C()
x.foo()
The "super" in x.foo() return a proxy for x that skips C.
Next, we call foo() on that proxy, which calls B's foo().
In B's foo(), "self" is the proxy. B's foo() passes the proxy to
super(), returning a new proxy for x that skips C and B. Finally, we
call foo() on the new proxy, which calls A's foo().
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5229>
_______________________________________
More information about the Python-bugs-list
mailing list