[Python-Dev] Re: my proposals about mros (was: perplexed by mro)
Fri, 4 Oct 2002 15:49:58 +0200
> I would still construct a linearized MRO out of it -- many places
> benefit from having it as a list rather than having to recurse down
> the inheritance lattice. But I agree that the naive algorithm seems
> to have some nice properties -- at the very least, it is easy to
> explain. :-)
> If Samuele agrees that the naive algorithm works better, I'll try to
> make it so in 2.3.
after cooking up the substitution example, I'm quite conviced that 2.2 mro is
the worst of our options: it produces easely counterintuitive results, and if
the conflict notion it needs is the one I think, it is the most prone to
reject hierarchies or in case we ignore conflict to produce very odd results.
So IMO our options are:
*) use the naive algo: it is easy to explain (the algorithm) but we should
live with the fact that it is not monotonic and I don't think it produces the
most natural results (because it considers what is encoutered at the end of a
dfs traversal, instead of what is at the beginning)
*) adopt C3:
(1) C3 is monotonic (it takes and merges respecting them the mros of the
superclasses, but in parallel, non sequentially like the current 2.2 mro algo)
(2) it respects also the inheritance lists of all superclasses; the paper I
cited claims that is something intuitively expected, and I tend to agree.
(3) it has another property, that basically enforces that, when this does not
conflicts with (1) and (2), the dfs order is respected.
How it works: one takes the mros of the direct superclasses and the inheritance
list of the considered class cl, and merges them as ordered sequences, in case
of a tie the mros of the classes appearing earlier in the inheritance list are
favored (this is what induces (3))
The intuitive difference with the current 2.2 mro is that C3 uses (3) only in
case of a tie, while the current 2.2 mro algo tries to enforce a a mix of (1)
and (3) at the same time.
>From the examples this does not seem not to have any evident benefit (unless we
consider the placement of b in ex5 such), and makes it the most complicated of
all algorithms from the point of view of understanding the outcomes.