MCPcopy Index your code
hub / github.com/python/cpython / _c3_merge

Function _c3_merge

Lib/functools.py:756–781  ·  view source on GitHub ↗

Merges MROs in *sequences* to a single MRO using the C3 algorithm. Adapted from https://docs.python.org/3/howto/mro.html.

(sequences)

Source from the content-addressed store, hash-verified

754################################################################################
755
756def _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
783def _c3_mro(cls, abcs=None):
784 """Computes the method resolution order using extended C3 linearization.

Callers 1

_c3_mroFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…