MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _c3_merge

Function _c3_merge

tools/python-3.11.9-amd64/Lib/functools.py:660–685  ·  view source on GitHub ↗

Merges MROs in *sequences* to a single MRO using the C3 algorithm. Adapted from https://www.python.org/download/releases/2.3/mro/.

(sequences)

Source from the content-addressed store, hash-verified

658################################################################################
659
660def _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
687def _c3_mro(cls, abcs=None):
688 """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