I am trying to understand the C3 Linearization Algorithm (Python) and I understood most part of it, but I just wonder why we should pick the first “valid candidate” incase there are more than one “valid candidates”
Let’s take an example as below:
class A: pass
class B: pass
class C: pass
class D(A, B): pass
class E(C, B): pass
class F(E,D,C): pass
When try F.mro()
, I get the following order:
F E D C A B O
I understood that the algorithms works as below:
L(F)=F + merge(L(E), L(D), L(C), EDC)
=F + merge(ECBO, DABO, CO, EDC)
=FE + merge(CBO, DABO, CO, DC)
= FED + merge(CBO, ABO, CO, C)
= FEDC + merge(BO,ABO,O)
= FEDCABO
But just look at the bold line, I think we can pick C or A, they are both valid. I know that the algorithm said pick the first one, but why not the second one? As I understand, there will be no conflict either if we pick A then pick C later on.