How does Python resolve the classic diamond inheritance problem, and what does "cooperative multiple inheritance" mean in practice?
Answer
In a diamond where `B` and `C` both inherit from `A`, and `D` inherits from both `B` and `C`, Python's C3-linearized MRO guarantees each ancestor appears exactly once, in a consistent order, so there is no ambiguity about which `A` is used. Cooperative multiple inheritance means every class in the hierarchy calls `super().__init__(**kwargs)` (rather than calling a specific parent class by name) so that each `__init__` in the chain runs exactly once, in MRO order, passing along whatever keyword arguments the next class in line still needs.
Strong answer includes
- C3-linearized MRO guarantees each ancestor appears once, consistently
- cooperative pattern uses super() instead of naming a specific parent
- every __init__ runs once in MRO order via chained super() calls
Practical example
If `B.__init__` and `C.__init__` both call `A.__init__` directly instead of
super().__init__(), `A.__init__` runs twice in a
D()instance; using
super().__init__()everywhere makes it run exactly once.