[Python-Dev] super() bug (?)
Guido van Rossum
guido@python.org
Fri, 07 Mar 2003 14:42:12 -0500
[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. 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)
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.
> that means implementation-wise
>
> f.__get__(None,D) should be called
>
> not f.__get__(D,D).
>
> _.__get__(None,D) would still do the right thing for static AND class methods:
>
> >>> def g(cls): pass
> ...
> >>> classmethod(g).__get__(None,D)
> <bound method type.g of <class '__main__.D'>>
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.
--Guido van Rossum (home page: http://www.python.org/~guido/)