print "PARENT altered()"
print "CHILD, BEFORE PARENT altered()"
super(Child, self).altered() # what are the arguments needed? Why Child and self?
print "CHILD, AFTER PARENT altered()"
super figures out which is the next class in the Method Resolution Order. The two arguments you pass in are what lets it figure that out -
self gives it the entire MRO via an attribute; the current class tells it where you are along the MRO right now. So what super is actually doing is basically:
def super(cls, inst): mro = inst.__class__.mro() # Always the most derived class return mro[mro.index(cls) + 1]
The reason it is the current class rather than the base class is because the entire point of having super is to have a function that works out what that base class is rather than having to refer to it explicitly - which can cause problems if the base class' name changes, if you don't know exactly what the parent class is called (think of factory functions like
namedtuple that spit out a new class), and especially in multi-inheritance situations (where the next class in the MRO mightn't be one of the current class' bases).