Why does super take a class name as the argument?

Leif K-Brooks eurleif at ecritters.biz
Fri Oct 15 22:27:13 CEST 2004


Chris Green wrote:
> I've done a bit of searching in the language reference and a couple
> pages referring the behavior of super() but I can't find any
> discussion of why super needs the name of the class as an argument.

Think about it. In this code:

class A(object):
     def do_stuff(self):
         print "A is doing stuff now."


class B(A):
     def do_stuff(self):
         super(B, self).do_stuff()
         print "B is doing stuff now."


class C(B):
     def do_stuff(self):
         super(C, self).do_stuff()
         print "C is doing stuff now."


How would Python know that B should call C's do_stuff() method instead 
of its own if there was no class argument? The self argument would be 
exactly the same when C called super() as when B called it. There has 
been some talk of making super into a language keyword instead of a 
type, though; that would eliminate the need to even pass in self.



More information about the Python-list mailing list