super() and type()

Rob Williscroft rtw at
Mon Nov 27 21:26:11 CET 2006

Chris Mellon wrote in
news:mailman.777.1164653627.32031.python-list at in

> I see super documented, and in use, as below (from the Python
> documentation) 
> class C(B):
>     def meth(self, arg):
>         super(C, self).meth(arg)
> I'd like to not write C all the time, so is there any problem with
> writing: 
> class C(B):
>     def meth(self, arg):
>         super(type(self), self).meth(arg)
> This seems to work in practice but I don't see it used anywhere and
> I'm worried what I might be missing.

Have you considered what happens if somebody writes:

class D(C):
  def meth(self, arg):
    super( D, self ).meth( arg )

> This was especially brought to my attention because pylint flags the
> second usage as invalid, and I'm not sure if it should be considered a
> false positive or not.

Nope, the type argument to super tells it where you are in the 
type hierarchy, type(self) is always the top of the hierarchy.


More information about the Python-list mailing list