[Python-3000] [Fwd: features i'd like [Python 3000] ... #3: fix super()]
jcarlson at uci.edu
Thu Dec 7 01:27:20 CET 2006
"Thomas Wouters" <thomas at python.org> wrote:
> On 12/6/06, Jan Grant <jan.grant at bristol.ac.uk> wrote:
> > On Mon, 4 Dec 2006, Ben Wing wrote:
> > > as a result, i imagine there's a strong urge to just hardcode the name
> > > of the parent
> > ^^^^^^^^^^
> > > -- super.meth(args) calls the superclass method `meth'
> > ^^^^^^^^^^^^^^
> > Python supports multiple inheritance, unlike Java; the design mantra is
> > "explicit is better than implicit" and "ambiguity should be an error".
> > Two! The two design mantras are...
> You forget that that's actually what super() is for. It does the right thing
> in the case of MI (and every other case, in fact :-)
Except for this one:
>>> class foo(object):
>>> class bar(foo):
... def method(self):
... super(bar, self).method()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in method
AttributeError: 'super' object has no attribute 'method'
Because of this kind of thing, I do my best to never produce code that
has a diamond inheritance structure (except for object), and always use
things like foo.method(self).
More information about the Python-3000