Exemple #1
0
 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:
               raise 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) -> ?:
               raise ?
           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)
Exemple #2
0
 def compute_types(self, defs):
   classes = (tuple(self.pytd_classes_for_unknowns()) +
              tuple(self.pytd_classes_for_call_traces()) +
              self.pytd_classes_for_namedtuple_instances())
   functions = tuple(self.pytd_functions_for_call_traces())
   aliases = tuple(self.pytd_aliases())
   ty = pytd_utils.Concat(
       self.pytd_for_types(defs),
       pytd_utils.CreateModule("unknowns", classes=classes,
                               functions=functions, aliases=aliases))
   ty = ty.Visit(optimize.CombineReturnsAndExceptions())
   ty = ty.Visit(optimize.PullInMethodClasses())
   ty = ty.Visit(visitors.DefaceUnresolved(
       [ty, self.loader.concat_all()], "~unknown"))
   return ty.Visit(visitors.AdjustTypeParameters())
Exemple #3
0
 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:
               raise X()
           def b(self) -> X[int]
   """)
   expected = textwrap.dedent("""
       class A(?):
           def a(self, a: A, b: ?, c: int) -> ?:
               raise ?
           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)
Exemple #4
0
 def test_deface_unresolved(self):
   builtins = self.Parse(textwrap.dedent("""
     class int:
       pass
   """))
   src = textwrap.dedent("""
       class A(X):
           def a(self, a: A, b: X, c: int) -> X:
               raise X()
           def b(self) -> X[int]: ...
   """)
   expected = textwrap.dedent("""
       from typing import Any
       class A(Any):
           def a(self, a: A, b: Any, c: int) -> Any:
               raise Any
           def b(self) -> Any: ...
   """)
   tree = self.Parse(src)
   new_tree = tree.Visit(visitors.DefaceUnresolved([tree, builtins]))
   new_tree.Visit(visitors.VerifyVisitor())
   self.AssertSourceEquals(new_tree, expected)