Why does super take a class name as the argument?

dataangel k04jg02 at kzoo.edu
Sat Oct 16 01:36:13 CEST 2004


Leif K-Brooks wrote:

> 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.

What's the going argument against it? Makes sense to me.




More information about the Python-list mailing list