Python super() continues attribute lookup after a selected class in the object’s method-resolution order.
Python super and method resolution: cooperate across mixins
Operation contract
The audit mixin and receipt mixin both extend the result returned by super(). The final pipeline therefore executes one ordered chain through both mixins and the base operation. A direct call to BasePolicy.tags would skip participants between the current class and the base. Cooperative composition requires compatible signatures and a shared agreement about who owns the result.
Failure and ownership boundary
Every participant must preserve the call contract. A mixin that omits super can end the chain; one that passes an argument the next method cannot accept can fail at runtime. The returned list is newly allocated by the terminal method, so extending it does not mutate a class-level shared default. Python inheritance: override behavior without inventing shared ownership and Python function arguments: avoid shared mutable defaults are prerequisites.
Working program
class BasePolicy:
def tags(self):
return ["base"]
class ReceiptPolicy(BasePolicy):
def tags(self):
return super().tags() + ["receipt"]
class AuditPolicy(BasePolicy):
def tags(self):
return super().tags() + ["audit"]
class DispatchPolicy(AuditPolicy, ReceiptPolicy):
pass
print([kind.__name__ for kind in DispatchPolicy.__mro__[:-1]])
print(DispatchPolicy().tags())Output
['DispatchPolicy', 'AuditPolicy', 'ReceiptPolicy', 'BasePolicy']
['base', 'receipt', 'audit']Costs and limits
The tiny chain has fixed depth. Repeated list concatenation copies intermediate results; with a long chain and growing tags, total copied entries can exceed the final result size.
Common Mistakes
- super refers to the next lookup position, not simply a named parent.
- Keep cooperative signatures compatible through the whole chain.
Connected lessons
Python inheritance: override behavior without inventing shared ownership, Python function arguments: avoid shared mutable defaults, Python descriptors: field validation and attribute precedence.
Follow the related contract
Python metaclasses: validate a class before registering its wire format.
Check the next state boundary
Python __init_subclass__: validate declarations without a custom metaclass.
