Why does super() require the class as the first argument?

Kevin Smith Kevin.Smith at sas.com
Thu Feb 3 14:02:12 EST 2005


I like the idea of the super() function, but it doesn't seem to solve 
the problem that I'm trying to fix.  I don't like hard-coding in calls 
to super classes using their names:

class A(object):
    def go(self):
        ...

class B(A):
    def go(self):
        ...
        A.go(self)

I don't like this because if I ever change the name of 'A', I have to go 
through all of the methods and change the names there too.  super() has 
the same problem, but I'm not sure why.  It seems like I should be able 
to do:

class B(A):
    def go(self):
        ...
        super(self).go()

I can create a super() that does this as follows:

_super = super
def super(obj, cls=None):
    if cls is None:
        return _super(type(obj), obj)
    return super(cls, obj)

I guess I'm just not sure why it wasn't done that way in the first place.

-- 
Kevin Smith
Kevin.Smith at sas.com



More information about the Python-list mailing list