[Python-Dev] super() bug (?)
Samuele Pedroni
pedronis@bluewin.ch
Fri, 7 Mar 2003 20:47:18 +0100
From: "Guido van Rossum" <guido@python.org>
> [Samuele]
> > >>> class C(object):
> > ... def f(self): pass
> > ...
> > >>> class D(C): pass
> > ...
> > >>> D.f
> > <unbound method D.f>
> > >>> super(D,D).f
> > <bound method D.f of <class '__main__.D'>>
> >
> > I think this should produce the same thing as D.f,
>
> Really? It makes no sense either way though.
It was sloppy phrased, super(D,D).f should return the same value as C.f, that
means an unbound method like D.f.
> super(D, D) only makes
> sense from inside a class method; there the first argument should be
> the current class and the second should be the cls argument to the
> class method, e.g.:
>
> class C(object):
> def cm(cls): pass
> cm = classmethod(cm)
>
> class D(C):
> def cm(cls):
> super(D, cls).cm() # ~Same as C.cm(cls)
you mean C.cm()
> And this works.
>
> I should also mention that super() should really only be used to call
> a method with the same name as the currently called method -- I see
> no use case for using super() with another method.
>
> It shouldn't be terribly hard to detect this situation and fix it
> (somewhere in super_init()) but unless you have a use case I'd
> rather consider this as a "don't care" situation.
>
no, but passing D,D even to classmethods __get__ is working but conceptually
bogus,
btw the clarifying example Python impl for super semantics at
http://www.python.org/2.2.2/descrintro.html#cooperation
is broken wrt to classmethods.