Inheritance and super()
A subclass can replace a parent's method or extend it. To extend, call the next version with super() and build on its result.
class Base:
def tags(self):
return ["base"]
class Logged(Base):
def tags(self):
return ["logged"] + super().tags()
class Cached(Base):
def tags(self):
return ["cached"] + super().tags()
class Service(Logged, Cached):
pass
print(Service().tags())
print([c.__name__ for c in Service.__mro__])The method resolution order
Every class has an __mro__, the order in which Python searches classes for an attribute. A class comes before its parents, and parents keep the order they are listed in.
super() means the next class in that order for this object, not simply the parent. In a Service, the super() inside Logged reaches Cached, a class Logged never mentions. If every class calls super() once, each method runs exactly once. This is cooperative inheritance.
__init__ follows the same rule. Make arguments keyword-only, let each class take its own and pass the rest on with super().__init__(**kwargs).
Your task
Make Colored and Bordered cooperative: each __init__ takes keyword-only arguments, keeps its own (color="black", width=1) and passes the rest to super().__init__, and each describe extends super().describe(). Then Badge(name="ok", color="red", width=2).describe() returns ["ok", "2px", "red"].
The explanation opens here once every check passes.