當前位置: 首頁>>代碼示例>>Python>>正文


Python pyfora.PyAstFreeVariableAnalyses類代碼示例

本文整理匯總了Python中pyfora.PyAstFreeVariableAnalyses的典型用法代碼示例。如果您正苦於以下問題:Python PyAstFreeVariableAnalyses類的具體用法?Python PyAstFreeVariableAnalyses怎麽用?Python PyAstFreeVariableAnalyses使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了PyAstFreeVariableAnalyses類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的pyfora.PyAstFreeVariableAnalyses類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。