Merges MROs in *sequences* to a single MRO using the C3 algorithm. Adapted from https://docs.python.org/3/howto/mro.html.
(sequences)
| 754 | ################################################################################ |
| 755 | |
| 756 | def _c3_merge(sequences): |
| 757 | """Merges MROs in *sequences* to a single MRO using the C3 algorithm. |
| 758 | |
| 759 | Adapted from https://docs.python.org/3/howto/mro.html. |
| 760 | |
| 761 | """ |
| 762 | result = [] |
| 763 | while True: |
| 764 | sequences = [s for s in sequences if s] # purge empty sequences |
| 765 | if not sequences: |
| 766 | return result |
| 767 | for s1 in sequences: # find merge candidates among seq heads |
| 768 | candidate = s1[0] |
| 769 | for s2 in sequences: |
| 770 | if candidate in s2[1:]: |
| 771 | candidate = None |
| 772 | break # reject the current head, it appears later |
| 773 | else: |
| 774 | break |
| 775 | if candidate is None: |
| 776 | raise RuntimeError("Inconsistent hierarchy") |
| 777 | result.append(candidate) |
| 778 | # remove the chosen candidate |
| 779 | for seq in sequences: |
| 780 | if seq[0] == candidate: |
| 781 | del seq[0] |
| 782 | |
| 783 | def _c3_mro(cls, abcs=None): |
| 784 | """Computes the method resolution order using extended C3 linearization. |