Merges MROs in *sequences* to a single MRO using the C3 algorithm. Adapted from https://www.python.org/download/releases/2.3/mro/.
(sequences)
| 658 | ################################################################################ |
| 659 | |
| 660 | def _c3_merge(sequences): |
| 661 | """Merges MROs in *sequences* to a single MRO using the C3 algorithm. |
| 662 | |
| 663 | Adapted from https://www.python.org/download/releases/2.3/mro/. |
| 664 | |
| 665 | """ |
| 666 | result = [] |
| 667 | while True: |
| 668 | sequences = [s for s in sequences if s] # purge empty sequences |
| 669 | if not sequences: |
| 670 | return result |
| 671 | for s1 in sequences: # find merge candidates among seq heads |
| 672 | candidate = s1[0] |
| 673 | for s2 in sequences: |
| 674 | if candidate in s2[1:]: |
| 675 | candidate = None |
| 676 | break # reject the current head, it appears later |
| 677 | else: |
| 678 | break |
| 679 | if candidate is None: |
| 680 | raise RuntimeError("Inconsistent hierarchy") |
| 681 | result.append(candidate) |
| 682 | # remove the chosen candidate |
| 683 | for seq in sequences: |
| 684 | if seq[0] == candidate: |
| 685 | del seq[0] |
| 686 | |
| 687 | def _c3_mro(cls, abcs=None): |
| 688 | """Computes the method resolution order using extended C3 linearization. |