Ejemplo n.º 1
0
 def __init__(self, superclasses=None, use_abcs=True):
     super(FindCommonSuperClasses, self).__init__()
     self._superclasses = builtins.GetBuiltinsPyTD().Visit(
         visitors.ExtractSuperClassesByName())
     self._superclasses.update(superclasses or {})
     if use_abcs:
         self._superclasses.update(abc_hierarchy.GetSuperClasses())
     self._subclasses = abc_hierarchy.Invert(self._superclasses)
Ejemplo n.º 2
0
def GetAllSubClasses(ast):
    """Compute a class->subclasses mapping.

  Args:
    ast: Parsed PYTD.

  Returns:
    A dictionary, mapping instances of pytd.TYPE (types) to lists of
    pytd.Class (the derived classes).
  """
    hierarchy = ast.Visit(visitors.ExtractSuperClasses())
    hierarchy = {
        cls: [superclass for superclass in superclasses]
        for cls, superclasses in hierarchy.items()
    }
    return abc_hierarchy.Invert(hierarchy)
Ejemplo n.º 3
0
def get_all_subclasses(asts):
  """Compute a class->subclasses mapping.

  Args:
    asts: A list of ASTs.

  Returns:
    A dictionary, mapping instances of pytd.TYPE (types) to lists of
    pytd.Class (the derived classes).
  """
  hierarchy = {}
  for ast in asts:
    hierarchy.update(ast.Visit(visitors.ExtractSuperClasses()))
  hierarchy = {cls: [superclass for superclass in superclasses
                     if (hasattr(superclass, "name") and
                         is_complete(superclass))]
               for cls, superclasses in hierarchy.items()
               if is_complete(cls)}
  # typically this is a fairly short list, e.g.:
  #  [ClassType(basestring), ClassType(int), ClassType(object)]
  return abc_hierarchy.Invert(hierarchy)
Ejemplo n.º 4
0
 def __init__(self, superclasses):
     self._superclasses = superclasses
     self._subclasses = abc_hierarchy.Invert(self._superclasses)