I'm sure it's documented somewhere, but here we go
The correct usage is super(MyClass, self)
The idea is that super allows for cooperative calls. It uses MyClass to locate
what class "above" to call.
This way you can something like that:
class A(object):
def bar(self):
print "A"
#getattr(super(A, self),"bar", lambda : None)()
class B(object):
def bar(self):
print "B"
#getattr(super(B, self),"bar", lambda : None)()
class C(A,B):
def bar(self):
print "C"
getattr(super(C, self),"bar", lambda : None)()
print "-" * 20, "no super in A/B"
C().bar()
class A(object):
def bar(self):
print "A"
getattr(super(A, self),"bar", lambda : None)()
class B(object):
def bar(self):
print "B"
getattr(super(B, self),"bar", lambda : None)()
class C(A,B):
def bar(self):
print "C"
getattr(super(C, self),"bar", lambda : None)()
print "-" * 20, "protected getattr/super in A/B"
C().bar()
class base(object):
def bar(self):
print "base"
class A(base):
def bar(self):
print "A"
getattr(super(A, self), "bar", lambda : None)()
class B(base):
def bar(self):
print "B"
getattr(super(B, self), "bar", lambda : None)()
class C(A,B):
def bar(self):
print "C"
getattr(super(C, self), "bar", lambda : None)()
print "-" * 20, "base class without super call"
C().bar()
This produces:
-------------------- no super in A/B
C
A
-------------------- protected getattr/super in A/B
C
A
B
-------------------- base class without super call
C
A
B
base
Andreas