[Python-3000] [Fwd: features i'd like [Python 3000] ... #3: fix super()]

Jim Jewett jimjjewett at gmail.com
Mon Dec 11 22:15:20 CET 2006


On 12/6/06, Jan Grant <jan.grant at bristol.ac.uk> wrote:
> On Mon, 4 Dec 2006, Ben Wing wrote:
> Commonly you know what the method is called at the point where you're
> typing "super" :-)

It still violated DRY.

For me, the single most annoying part is the assymetry with regular calls.

    super(ClassName, self).method(args_excluding_self)

I understand the reason (super needs the "self", and then returns a
bound method), but it still jars.  That it still doesn't quite solve
the problem (e.g., what if the name of the class gets rebound?) makes
it seem almost bad.

What are the use cases for super?  The ones I can think of are:

(1)  I'm writing a mixin.  I want to call the next method (if there is
one) with exactly my arguments.  If the method doesn't exist on any
superclass, then a no-op is fine.

(2)  I'm calling a parent class' method with exactly my arguments.  If
the method doesn't exist, then an AttributeError is appropriate.  (But
that probably means I made a typo, and shouldn't have had to repeat
the method name in the first place.)

(3)  I'm calling a parent class with changed arguments.  (Typically,
to throw away some arguments that I used for my extensions, or to fill
in defaults.)

(4)  I'm calling a different method on the parent, *and* I want to
avoid calling that method from my own or a further derived class.  (Is
this ever a good pattern?)

(5) ...?  I have a feeling I'm missing some cases with different
requirements, but can't think what they are.

The fact that, at define time, I can't get hold of my class object
yet, makes all super calls fragile.  (Though perhaps not as fragile as
the alternative.)

Cases (1) and (2) are common enough that there should be a way to do
them both easily, and it would be great if the argument list did not
have to be repeated.  By not repeating it, the cases that do make
changes would stand out more.

Cases (3) and (4) require an explicit argument list, but it would
still be helpful if that list could match the signature to the extent
possible (with "self", for instance).

-jJ


More information about the Python-3000 mailing list