def testGetBasesInMRO(self): ast = self.parser.Parse(textwrap.dedent(""" T = TypeVar("T") class Foo(Generic[T]): pass class Bar(Foo[int]): pass """)) b, t = builtins.GetBuiltinsAndTyping() ast = ast.Visit(visitors.LookupExternalTypes( {"__builtin__": b, "typing": t}, full_names=True)) ast = ast.Visit(visitors.NamedTypeToClassType()) mro = utils.GetBasesInMRO(ast.Lookup("Bar"), lookup_ast=ast) self.assertListEqual(["Foo", "typing.Generic", "__builtin__.object"], [t.name for t in mro])
def _MaybeRemoveSignature(self, name, sig): """Visit a Signature and return None if we can remove it.""" if (not sig.params or sig.params[0].name != "self" or not isinstance(sig.params[0].type, pytd.ClassType)): return sig # Not a method cls = sig.params[0].type.cls if cls is None: # TODO(kramm): Remove once pytype stops generating ClassType(name, None). return sig try: if self._FindNameAndSig(utils.GetBasesInMRO(cls), name, sig.Replace(params=sig.params[1:])): return None # remove (see VisitFunction) except utils.MROError: return sig return sig