Locating a Method’s super
In this lesson, you find out where a method’s super starts looking.
At the tool library, a kit describes itself for its label, and a tagged kit wraps that text in a tag. In
Python, the describe in TaggedKit calls super().describe(), which finds the next class after
TaggedKit in the receiver’s MRO, so the receiver decides what comes next:
class Kit:
def __init__(self, code):
self.code = code
def describe(self):
return f"{self.code}: base"
class TaggedKit(Kit):
def describe(self):
return f"tag[{super().describe()}]"
tagged = TaggedKit("KIT-17")
print(tagged.describe())
print([c.__name__ for c in TaggedKit.__mro__])
For a tagged kit, that list runs TaggedKit, Kit, then object, so super() reaches Kit: