On Sat, Mar 26, 2022 at 06:15:57PM -0000, malmiteria wrote:
class C(A, B): pass ```
Today, a code such as ```C().method()``` works without any problems
Actually, no, it does not. Only the A.method() runs, because A was not designed for multiple-inheritance. C inherits from both A and B, but only calls one of the methods.
except of course when the method you wanted to refer to was the method from B.
Why are you inheriting from A if you don't want to inherit from A?
If class A and B both come from libraries you don't own, and for some reason have each a method named the same (named run, for example) the run method of C is silently ignoring the run method of B.
Right. Multiple inheritence in Python is **cooperative** -- all of the classes in question have to work together. If they don't, as A and B don't, bad things happen. You can't just inherit from arbitrary classes that don't work together. "Uncooperative multiple inheritance" is an unsolvable problem, and is best refactored using composition instead. -- Steve