C3 linearization

In other words, the output of C3 superclass linearization is a deterministic Method Resolution Order (MRO).

[3] It has been chosen as the default algorithm for method resolution in Python 2.3 (and newer),[4][5] Raku,[6] Parrot,[7] Solidity, and PGF/TikZ's Object-Oriented Programming module.

[9] An extension implementation for earlier versions of Perl 5 named Class::C3 exists on CPAN.

[10] Python's Guido van Rossum summarizes C3 superclass linearization thus:[11] Basically, the idea behind C3 is that if you write down all of the ordering rules imposed by inheritance relationships in a complex class hierarchy, the algorithm will determine a monotonic ordering of the classes that satisfies all of them.

If at some point no good head can be selected, because the heads of all remaining lists appear in any one tail of the lists, then the merge is impossible to compute due to inconsistent orderings of dependencies in the inheritance hierarchy and no linearization of the original class exists.

A dependency graph for the C3 linearization example.