def testDefaceUnresolved2(self): builtins = self.Parse( textwrap.dedent(""" from typing import Generic, TypeVar class int(object): pass T = TypeVar("T") class list(Generic[T]): pass """)) src = textwrap.dedent(""" from typing import Union class A(X): def a(self, a: A, b: X, c: int) -> X raises X def c(self) -> Union[list[X], int] """) expected = textwrap.dedent(""" from typing import Union class A(?): def a(self, a: A, b: ?, c: int) -> ? raises ? def c(self) -> Union[list[?], int] """) tree = self.Parse(src) new_tree = tree.Visit(visitors.DefaceUnresolved([tree, builtins])) new_tree.Visit(visitors.VerifyVisitor()) self.AssertSourceEquals(new_tree, expected)
def compute_types(self, defs, ignore): self.program.Freeze() ty = pytd_utils.Concat( self.pytd_for_types(defs, ignore), pytd.TypeDeclUnit( "unknowns", (), tuple(self.pytd_classes_for_unknowns()) + tuple(self.pytd_classes_for_call_traces()), tuple(self.pytd_functions_for_call_traces()))) ty = ty.Visit(optimize.PullInMethodClasses()) ty = ty.Visit(visitors.DefaceUnresolved( [ty, self.loader.concat_all()], "~unknown")) return ty
def compute_types(self, defs): ty = pytd_utils.Concat( self.pytd_for_types(defs), pytd.TypeDeclUnit( "unknowns", constants=tuple(), type_params=tuple(self.pytd_typevars()), classes=tuple(self.pytd_classes_for_unknowns()) + tuple(self.pytd_classes_for_call_traces()), functions=tuple(self.pytd_functions_for_call_traces()), aliases=tuple(self.pytd_aliases()))) ty = ty.Visit(optimize.PullInMethodClasses()) ty = ty.Visit(visitors.DefaceUnresolved( [ty, self.loader.concat_all()], "~unknown")) return ty.Visit(visitors.AdjustTypeParameters())
def testDefaceUnresolved(self): builtins = self.Parse(textwrap.dedent(""" class int(object): pass """)) src = textwrap.dedent(""" class A(X): def a(self, a: A, b: X, c: int) -> X raises X def b(self) -> X[int] """) expected = textwrap.dedent(""" class A(?): def a(self, a: A, b: ?, c: int) -> ? raises ? def b(self) -> ? """) tree = self.Parse(src) new_tree = tree.Visit(visitors.DefaceUnresolved([tree, builtins])) new_tree.Visit(visitors.VerifyVisitor()) self.AssertSourceEquals(new_tree, expected)