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)
def test_expand(self): src = textwrap.dedent(""" from typing import Union def foo(a: Union[int, float], z: Union[complex, str], u: bool) -> file: ... def bar(a: int) -> Union[str, unicode]: ... """) new_src = textwrap.dedent(""" from typing import Union 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) -> Union[str, unicode]: ... """) self.AssertSourceEquals( self.ApplyVisitorToString(src, visitors.ExpandSignatures()), new_src)
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_utils.Print(signature) break else: faulty_signature = "" raise FlawedQuery("Bad call\n%s%s\nagainst:\n%s" % (escape.unpack_partial(call_record.name), faulty_signature, pytd_utils.Print(complete))) solver.always_true(formula)