Example #1
0
 def testExpand(self):
   src = textwrap.dedent("""
       def foo(a: int or float, z: complex or str, u: bool) -> file
       def bar(a: int) -> str or unicode
   """)
   new_src = textwrap.dedent("""
       def foo(a: int, z: complex, u: bool) -> file
       def foo(a: int, z: str, u: bool) -> file
       def foo(a: float, z: complex, u: bool) -> file
       def foo(a: float, z: str, u: bool) -> file
       def bar(a: int) -> str or unicode
   """)
   self.AssertSourceEquals(
       self.ApplyVisitorToString(src, visitors.ExpandSignatures()),
       new_src)
Example #2
0
 def match_call_record(self, matcher, solver, call_record, complete):
   """Match the record of a method call against the formal signature."""
   assert is_partial(call_record)
   assert is_complete(complete)
   formula = (
       matcher.match_Function_against_Function(call_record, complete, {}))
   if formula is booleq.FALSE:
     cartesian = call_record.Visit(visitors.ExpandSignatures())
     for signature in cartesian.signatures:
       formula = matcher.match_Signature_against_Function(
           signature, complete, {})
       if formula is booleq.FALSE:
         faulty_signature = pytd.Print(signature)
         break
     else:
       faulty_signature = ""
     raise FlawedQuery("Bad call\n%s%s\nagainst:\n%s" % (
         type_match.unpack_name_of_partial(call_record.name),
         faulty_signature, pytd.Print(complete)))
   solver.always_true(formula)
Example #3
0
 def match_Signature_against_Function(self, sig, f, subst, skip_self=False):  # pylint: disable=invalid-name
     return booleq.And(
         booleq.Or(
             self.match_Signature_against_Signature(
                 inner, s, subst, skip_self) for s in f.signatures)
         for inner in sig.Visit(visitors.ExpandSignatures()))