Merges MROs in *sequences* to a single MRO using the C3 algorithm. Adapted from https://docs.python.org/3/howto/mro.html.
(sequences)
| 733 | ################################################################################ |
| 734 | |
| 735 | def _c3_merge(sequences): |
| 736 | """Merges MROs in *sequences* to a single MRO using the C3 algorithm. |
| 737 | |
| 738 | Adapted from https://docs.python.org/3/howto/mro.html. |
| 739 | |
| 740 | """ |
| 741 | result = [] |
| 742 | while True: |
| 743 | sequences = [s for s in sequences if s] # purge empty sequences |
| 744 | if not sequences: |
| 745 | return result |
| 746 | for s1 in sequences: # find merge candidates among seq heads |
| 747 | candidate = s1[0] |
| 748 | for s2 in sequences: |
| 749 | if candidate in s2[1:]: |
| 750 | candidate = None |
| 751 | break # reject the current head, it appears later |
| 752 | else: |
| 753 | break |
| 754 | if candidate is None: |
| 755 | raise RuntimeError("Inconsistent hierarchy") |
| 756 | result.append(candidate) |
| 757 | # remove the chosen candidate |
| 758 | for seq in sequences: |
| 759 | if seq[0] == candidate: |
| 760 | del seq[0] |
| 761 | |
| 762 | def _c3_mro(cls, abcs=None): |
| 763 | """Computes the method resolution order using extended C3 linearization. |