How to use the retype.reapply_all function in retype

To help you get started, we’ve selected a few retype examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ambv / retype / tests / test_retype.py View on Github external
def assertReapply(
        self, pyi_txt, src_txt, expected_txt, *, incremental=False, replace_any=False
    ):
        pyi = ast3.parse(dedent(pyi_txt))
        src = lib2to3_parse(dedent(src_txt))
        expected = lib2to3_parse(dedent(expected_txt))
        assert isinstance(pyi, ast3.Module)
        flags = ReApplyFlags(replace_any=replace_any, incremental=incremental)
        reapply_all(pyi.body, src, flags)
        fix_remaining_type_comments(src, flags)
        self.longMessage = False
        self.assertEqual(expected, src, f"\n{expected!r} != \n{src!r}")
github ambv / retype / tests / test_retype.py View on Github external
def assertReapplyRaises(
        self,
        pyi_txt,
        src_txt,
        expected_exception,
        *,
        incremental=False,
        replace_any=False,
    ):
        flags = ReApplyFlags(replace_any=replace_any, incremental=incremental)

        with self.assertRaises(expected_exception) as ctx:
            pyi = ast3.parse(dedent(pyi_txt))
            src = lib2to3_parse(dedent(src_txt))
            assert isinstance(pyi, ast3.Module)
            reapply_all(pyi.body, src, flags)
            fix_remaining_type_comments(src, flags)
        return ctx.exception
github ambv / retype / tests / test_retype.py View on Github external
def assertReapplyVisible(
        self, pyi_txt, src_txt, expected_txt, *, incremental=False, replace_any=False
    ):
        flags = ReApplyFlags(replace_any=replace_any, incremental=incremental)
        pyi = ast3.parse(dedent(pyi_txt))
        src = lib2to3_parse(dedent(src_txt))
        expected = lib2to3_parse(dedent(expected_txt))
        assert isinstance(pyi, ast3.Module)
        reapply_all(pyi.body, src, flags)
        fix_remaining_type_comments(src, flags)
        self.longMessage = False
        self.assertEqual(
            str(expected), str(src), f"\n{str(expected)!r} != \n{str(src)!r}"
        )