Why does super take a class name as the argument?

Scott David Daniels Scott.Daniels at Acm.Org
Fri Oct 15 10:52:05 EDT 2004


Chris Green wrote:
> ... I can't find any
> discussion of why super needs the name of the class as an argument.
> 
> super(self).method() seems like super could just do the right
> thing...
It could "just do the right thing", but not as a function, only as a
compiler magic thingamiebob.  When methods are being translated, they
are ordinary function definitions, and the class for which they will
become a method does not exist.  By including the name of the class
itself, rather than the name of the (or a) super class, super can search
in the "mro" for the class, and find the next class in that order after
the given class.  "super" seems to me to have the "explicit is better
than implicit" flavor without forcing you to know the whole inheritance
structure.

-Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list