super() not a panacea?

John Roth newsgroups at jhrothjr.com
Wed Feb 18 06:52:02 EST 2004


"Clarence Gardner" <clarence at netlojix.net> wrote in message
news:pan.2004.02.17.18.59.19.712556 at netlojix.net...
>
> The super object is considered a solution to the "diamond problem".
> However, it generally requires that the ultimate base class know that it
> is last in the method resolution order, and hence it should not itself
> use super (as well as supplying the ultimate implementation of an
> overridden method.)
>
> However, a problem comes up if that ultimate base class is also the base
> class for another which inherits from it and another independent base
> class also providing that method. This results in a situation where the
> first base class is now required to use super in order to propogate the
> call chain over to the new classes, in the case of the object being an
> instance of the newly-added subclass, but still must not use super in
> the case of the object being an instance of the original (bottom of
> diamond) class.

Have you reviewed the current method resolution order?

http://www.python.org/2.3/mro.html

I believe it was developed specifically to deal with this
problem.

Also, I'm firmly of the opinion that if you've got one of these
bizzare cases, you've got a design smell that should be dealt
with immediately, rather than expecting rational behavior from
language facilities.

"Rational," in this case, usually means "do what I need done
in this specific case, regardless of what anyone else thinks."

John Roth





More information about the Python-list mailing list