• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyfora.PyAstFreeVariableAnalyses类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_member_acces_after_possible_assignment

    def test_member_acces_after_possible_assignment(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                def f():
                    if 0:
                       x = 2
                    x.y
                """
                )
            )
        expectedResult = set(['x'])
        self.assertEqual(
            expectedResult,
            PyAstUninstantiatedVariablesAnalysis.
                collectPossiblyUninitializedLocalVariables(tree)
            )

        self.assertEqual(
            set(),
            PyAstFreeVariableAnalyses.getFreeVariables(tree)
            )

        self.assertEqual(
            set(),
            PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains(tree)
            )        
开发者ID:nkhuyu,项目名称:ufora,代码行数:27,代码来源:PyAstPossiblyUninitializedVariables_test.py


示例2: 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:nkhuyu,项目名称:ufora,代码行数:12,代码来源:PyAstFreeVariableAnalyses_test.py


示例3: collectPossiblyUninitializedLocalVariablesInScope

def collectPossiblyUninitializedLocalVariablesInScope(pyAstNode):
    boundVariables = PyAstFreeVariableAnalyses.collectBoundVariablesInScope(pyAstNode)
    visitor = _PossiblyUninitializedLocalVariablesInScopeVisitor(
        pyAstNode,
        boundVariables)
    possiblyUninitializedVariables = visitor.getPossiblyUninitializedLocalVariablesInScope()
    return possiblyUninitializedVariables
开发者ID:nkhuyu,项目名称:ufora,代码行数:7,代码来源:PyAstUninstantiatedVariablesAnalysis.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:nkhuyu,项目名称:ufora,代码行数:8,代码来源:PyAstFreeVariableAnalyses_test.py


示例5: test_CollectBoundVariablesInScope_classDef

    def test_CollectBoundVariablesInScope_classDef(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                v0 = z
                class c(x):
                    v1
                    v2 = 2
                    v3 += 3
                    (v4, v5), v6 = w
                v7 = zz
                """
            )
        )

        self.assertEqual(set(["v0", "v7"]), PyAstFreeVariableAnalyses.collectBoundVariablesInScope(tree))
        self.assertEqual(set(["c"]), PyAstFreeVariableAnalyses.collectBoundNamesInScope(tree))
开发者ID:nkhuyu,项目名称:ufora,代码行数:17,代码来源:PyAstCollectBoundVariablesInScope_test.py


示例6: 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:nkhuyu,项目名称:ufora,代码行数:9,代码来源:PyAstFreeVariableAnalyses_test.py


示例7: 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:nkhuyu,项目名称:ufora,代码行数:13,代码来源:PyAstFreeVariableAnalyses_test.py


示例8: 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:nkhuyu,项目名称:ufora,代码行数:13,代码来源:PyAstFreeVariableAnalyses_test.py


示例9: 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:nkhuyu,项目名称:ufora,代码行数:13,代码来源:PyAstFreeVariableAnalyses_test.py


示例10: 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:nkhuyu,项目名称:ufora,代码行数:13,代码来源: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:nkhuyu,项目名称:ufora,代码行数:13,代码来源:PyAstFreeVariableAnalyses_test.py


示例12: 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:nkhuyu,项目名称:ufora,代码行数:13,代码来源:PyAstFreeVariableAnalyses_test.py


示例13: 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:nkhuyu,项目名称:ufora,代码行数:13,代码来源:PyAstFreeVariableAnalyses_test.py


示例14: 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:nkhuyu,项目名称:ufora,代码行数:13,代码来源:PyAstFreeVariableAnalyses_test.py


示例15: 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:nkhuyu,项目名称:ufora,代码行数:22,代码来源:PyAstFreeVariableAnalyses_test.py


示例16: 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:nkhuyu,项目名称:ufora,代码行数:13,代码来源:PyAstFreeVariableAnalyses_test.py


示例17: test_freeVariables_functionCalls

    def test_freeVariables_functionCalls(self):
        tree = ast.parse(
            textwrap.dedent(
                """
                x = 2
                f(x, y, z = 2, w = x, q = free, *args, **kwargs)
                """
                )
            )

        self.assertEqual(
            set(['f', 'y', 'args', 'kwargs', 'free']),
            PyAstFreeVariableAnalyses.getFreeVariables(tree)
            )
开发者ID:nkhuyu,项目名称:ufora,代码行数:14,代码来源:PyAstFreeVariableAnalyses_test.py


示例18: 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:nkhuyu,项目名称:ufora,代码行数:14,代码来源:PyAstFreeVariableAnalyses_test.py


示例19: test_freeVariables_name_substring_bug

 def test_freeVariables_name_substring_bug(self):
     tree = ast.parse(
         textwrap.dedent(
             """
             al = 10
             l
             """
             )
         )
     expectedResult = set(['l'])
     self.assertEqual(
         expectedResult,
         PyAstFreeVariableAnalyses.getFreeVariables(tree)
         )
开发者ID:nkhuyu,项目名称:ufora,代码行数:14,代码来源:PyAstFreeVariableAnalyses_test.py


示例20: test_freeVariables_withStatement

 def test_freeVariables_withStatement(self):
     tree = ast.parse(
         textwrap.dedent(
             """
             def f(arg):
                 with x as e:
                     return e
             """
             )
         )
     self.assertEqual(
         set(['x']),
         PyAstFreeVariableAnalyses.getFreeVariables(tree)
         )
开发者ID:nkhuyu,项目名称:ufora,代码行数:14,代码来源:PyAstFreeVariableAnalyses_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyAst.PyAstFreeVariableAnalyses类代码示例发布时间:2022-05-25
下一篇:
Python pyfmt.format_code函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap