Possible pitfalls — MRO inconsistency
MRO can report definition inconsistencies when a subtle change in the class D
definition is introduced, which is possible when you work with complex class hierarchies.
Imagine that you have changed the class D
definition from:
class D(B, C):
pass
to:
class D(A, C):
pass
Now when you run the code (the code is presented in the right pane, implement the change), you get:
Traceback (most recent call last):
File "diamond.py", line 13, in
class D(A, C):
TypeError: Cannot create a consistent method resolution order (MRO) for bases A, C
output
This message informs us that the MRO algorithm had problems determining which method (originating from the A or C classes) should be called.