当前位置: 首页>>代码示例>>Python>>正文


Python pyAst.PyAstFreeVariableAnalyses类代码示例

本文整理汇总了Python中pyfora.pyAst.PyAstFreeVariableAnalyses的典型用法代码示例。如果您正苦于以下问题:Python PyAstFreeVariableAnalyses类的具体用法?Python PyAstFreeVariableAnalyses怎么用?Python PyAstFreeVariableAnalyses使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PyAstFreeVariableAnalyses类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_freeVariables_globalStmt_2

 def test_freeVariables_globalStmt_2(self):
     tree = ast.parse(
         textwrap.dedent(
             """
             def f():
                 global x
                 return x
             """
         )
     )
     with self.assertRaises(Exceptions.PythonToForaConversionError):
         PyAstFreeVariableAnalyses.getFreeVariables(tree)
开发者ID:vishnur,项目名称:ufora,代码行数:12,代码来源:PyAstFreeVariableAnalyses_test.py

示例2: test_freeVariables_CompsAndGenExp2

 def test_freeVariables_CompsAndGenExp2(self):
     tree = ast.parse(
         textwrap.dedent(
             """
             [elt01 for elt1 in container1]
             {elt02 for elt2 in container2}
             {elt03: elt04 for elt4 in container4 for elt3 in container3}
             (x0*y0 for x in range(10) for y in bar(x))
             """
         )
     )
     expectedResult = set(
         [
             "container1",
             "container2",
             "container3",
             "container4",
             "bar",
             "range",
             "elt01",
             "elt02",
             "elt03",
             "elt04",
             "x0",
             "y0",
         ]
     )
     self.assertEqual(expectedResult, PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:28,代码来源:PyAstFreeVariableAnalyses_test.py

示例3: test_freeVariables_function_context

    def test_freeVariables_function_context(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                def fib(x):
                    if x < 2:
                        return 1
                    else:
                        return fib(x-1) + fib(x-2)
                """
            )
        )

        self.assertEqual(set([]), PyAstFreeVariableAnalyses.getFreeVariables(tree.body[0], isClassContext=False))

        self.assertEqual(set(["fib"]), PyAstFreeVariableAnalyses.getFreeVariables(tree.body[0], isClassContext=True))
开发者ID:vishnur,项目名称:ufora,代码行数:16,代码来源:PyAstFreeVariableAnalyses_test.py

示例4: test_memberAccessChain_2

    def test_memberAccessChain_2(self):
        tree = ast.parse("(1).y.z.w")

        self.assertIsNone(
            PyAstFreeVariableAnalyses._memberAccessChainOrNone(
                tree.body[0].value
                )
            )
开发者ID:Sandy4321,项目名称:ufora,代码行数:8,代码来源:PyAstFreeVariableAnalyses_test.py

示例5: test_memberAccessChain_1

    def test_memberAccessChain_1(self):
        tree = ast.parse("x.y.z.w")

        self.assertEqual(
            ('x', 'y', 'z', 'w'),
            PyAstFreeVariableAnalyses._memberAccessChainOrNone(
                tree.body[0].value
                )
            )
开发者ID:Sandy4321,项目名称:ufora,代码行数:9,代码来源:PyAstFreeVariableAnalyses_test.py

示例6: test_freeVariables_Assign

    def test_freeVariables_Assign(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                (x, y), z = w
                """
            )
        )

        self.assertEqual(set(["w"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py

示例7: test_freeVariables_classDef_1

    def test_freeVariables_classDef_1(self):
        tree = ast.parse(
            textwrap.dedent(
                """class C(object):
                    def f(x):
                        return len(f)"""
            )
        )

        self.assertEqual(set(["object", "len", "f"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py

示例8: test_freeVariables_functionDef_2

    def test_freeVariables_functionDef_2(self):
        tree = ast.parse(
            textwrap.dedent(
                """def outer():
                    def f(x):
                        return len(f)"""
            )
        )

        self.assertEqual(set(["len"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py

示例9: test_freeVariables_Lambda_1

    def test_freeVariables_Lambda_1(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                lambda x, y = z, *args, **kwargs: (x, y, args, kwargs, free)
                """
            )
        )

        self.assertEqual(set(["z", "free"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py

示例10: test_freeVariables_DictComp_1

    def test_freeVariables_DictComp_1(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                d = { x: y for x, y in o.f() }
                """
            )
        )

        self.assertEqual(set(["o"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py

示例11: test_freeVariables_ListComp_2

    def test_freeVariables_ListComp_2(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                [val for val in x if val == free]
                """
            )
        )

        self.assertEqual(set(["free", "x"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py

示例12: test_freeVariables_DictComp_2

    def test_freeVariables_DictComp_2(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                d = { x1: y1 for x2, y2 in o.f() }
                """
            )
        )

        self.assertEqual(set(["o", "x1", "y1"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py

示例13: test_freeVariables_SetComp_1

    def test_freeVariables_SetComp_1(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                {v for x in q}
                """
            )
        )

        self.assertEqual(set(["v", "q"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py

示例14: test_freeVariables_ListComp_4

    def test_freeVariables_ListComp_4(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
                """
            )
        )

        self.assertEqual(set(), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py

示例15: test_freeVariables_ListComp_3

    def test_freeVariables_ListComp_3(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                x = [1,2,3]
                [y for val in x]
                """
            )
        )

        self.assertEqual(set(["y"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:11,代码来源:PyAstFreeVariableAnalyses_test.py


注:本文中的pyfora.pyAst.PyAstFreeVariableAnalyses类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。