Example #1
0
 def testMROMerge(self):
     self.assertEquals([], utils.MROMerge([[], []]))
     self.assertEquals([1], utils.MROMerge([[], [1]]))
     self.assertEquals([1], utils.MROMerge([[1], []]))
     self.assertEquals([1, 2], utils.MROMerge([[1], [2]]))
     self.assertEquals([1, 2], utils.MROMerge([[1, 2], [2]]))
     self.assertEquals([1, 2, 3, 4], utils.MROMerge([[1, 2, 3], [2, 4]]))
     self.assertEquals([1, 2, 3], utils.MROMerge([[1, 2], [1, 2, 3]]))
     self.assertEquals([1, 2], utils.MROMerge([[1, 1], [2, 2]]))
     self.assertEquals([1, 2, 3, 4, 5, 6],
                       utils.MROMerge([[1, 3, 5], [2, 3, 4], [4, 5, 6]]))
     self.assertEquals([1, 2, 3], utils.MROMerge([[1, 2, 1], [2, 3, 2]]))
Example #2
0
def compute_mro(c):
    """Compute the class precedence list (mro) according to C3.

  This code is copied from the following URL with print statements removed.
  https://www.python.org/download/releases/2.3/mro/

  Args:
    c: The Class to compute the MRO for. This needs to be an instance
      with the members "mro" and "bases".
  Returns:
    A list of Class objects in Method Resolution Order.
  """
    return tuple(
        pytd_utils.MROMerge([[c]] + [list(base.mro) for base in c.bases()] +
                            [list(c.bases())]))