Ejemplo n.º 1
0
 def testOptional(self):
   ast = parser.parse_string(textwrap.dedent("""
     def left(a: int) -> int
     def right(a: int, ...) -> int
   """))
   m = type_match.TypeMatch()
   self.assertEquals(m.match(ast.Lookup("left"), ast.Lookup("right"), {}),
                     booleq.TRUE)
Ejemplo n.º 2
0
 def testOptional(self):
     ast = parser.parse_string(
         textwrap.dedent("""
   def left(a: int) -> int
   def right(a: int, ...) -> int
 """))
     m = type_match.TypeMatch()
     self.assertEquals(m.match(ast.Lookup("left"), ast.Lookup("right"), {}),
                       booleq.TRUE)
Ejemplo n.º 3
0
def ParseBuiltinsFile(filename):
  """GetBuiltins(), but for a single file, not adding to builtins.modules.

  Only used in tests, e.g. for loading reduced or specialized builtin files.

  Args:
    filename: Filename, relative to pytypedecl/builtins/
  Returns:
    A PyTypeDeclUnit for a single module.
  """
  return parser.parse_string(_FindBuiltinFile(filename))
Ejemplo n.º 4
0
def ParseBuiltinsFile(filename):
    """GetBuiltins(), but for a single file, not adding to builtins.modules.

  Only used in tests, e.g. for loading reduced or specialized builtin files.

  Args:
    filename: Filename, relative to pytypedecl/builtins/
  Returns:
    A PyTypeDeclUnit for a single module.
  """
    return parser.parse_string(_FindBuiltinFile(filename))
Ejemplo n.º 5
0
 def testGeneric(self):
   ast = parser.parse_string(textwrap.dedent("""
     class A<T extends nothing>(nothing):
       pass
     left: A<?>
     right: A<?>
   """))
   ast = visitors.LookupClasses(ast)
   m = type_match.TypeMatch()
   self.assertEquals(m.match_type_against_type(
       ast.Lookup("left").type,
       ast.Lookup("right").type, {}), booleq.TRUE)
Ejemplo n.º 6
0
 def testClassMatch(self):
   ast = parser.parse_string(textwrap.dedent("""
     class Left(nothing):
       def method(self) -> ?
     class Right(nothing):
       def method(self) -> ?
       def method2(self) -> ?
   """))
   ast = visitors.LookupClasses(ast)
   m = type_match.TypeMatch()
   left, right = ast.Lookup("Left"), ast.Lookup("Right")
   self.assertEquals(m.match(left, right, {}), booleq.TRUE)
   self.assertNotEquals(m.match(right, left, {}), booleq.TRUE)
Ejemplo n.º 7
0
 def testGeneric(self):
     ast = parser.parse_string(
         textwrap.dedent("""
   class A<T extends nothing>(nothing):
     pass
   left: A<?>
   right: A<?>
 """))
     ast = visitors.LookupClasses(ast)
     m = type_match.TypeMatch()
     self.assertEquals(
         m.match_type_against_type(
             ast.Lookup("left").type,
             ast.Lookup("right").type, {}), booleq.TRUE)
Ejemplo n.º 8
0
 def testClassMatch(self):
     ast = parser.parse_string(
         textwrap.dedent("""
   class Left(nothing):
     def method(self) -> ?
   class Right(nothing):
     def method(self) -> ?
     def method2(self) -> ?
 """))
     ast = visitors.LookupClasses(ast)
     m = type_match.TypeMatch()
     left, right = ast.Lookup("Left"), ast.Lookup("Right")
     self.assertEquals(m.match(left, right, {}), booleq.TRUE)
     self.assertNotEquals(m.match(right, left, {}), booleq.TRUE)
Ejemplo n.º 9
0
 def testSubclasses(self):
   ast = parser.parse_string(textwrap.dedent("""
     class A(nothing):
       pass
     class B(A):
       pass
     a : A
     def left(a: B) -> B
     def right(a: A) -> A
   """))
   ast = visitors.LookupClasses(ast)
   m = type_match.TypeMatch({ast.Lookup("a").type: [ast.Lookup("B")]})
   left, right = ast.Lookup("left"), ast.Lookup("right")
   self.assertEquals(m.match(left, right, {}), booleq.TRUE)
   self.assertNotEquals(m.match(right, left, {}), booleq.TRUE)
Ejemplo n.º 10
0
 def testSubclasses(self):
     ast = parser.parse_string(
         textwrap.dedent("""
   class A(nothing):
     pass
   class B(A):
     pass
   a : A
   def left(a: B) -> B
   def right(a: A) -> A
 """))
     ast = visitors.LookupClasses(ast)
     m = type_match.TypeMatch({ast.Lookup("a").type: [ast.Lookup("B")]})
     left, right = ast.Lookup("left"), ast.Lookup("right")
     self.assertEquals(m.match(left, right, {}), booleq.TRUE)
     self.assertNotEquals(m.match(right, left, {}), booleq.TRUE)