本文整理汇总了Python中pyfora.pyAst.PyAstFreeVariableAnalyses.getFreeVariables方法的典型用法代码示例。如果您正苦于以下问题:Python PyAstFreeVariableAnalyses.getFreeVariables方法的具体用法?Python PyAstFreeVariableAnalyses.getFreeVariables怎么用?Python PyAstFreeVariableAnalyses.getFreeVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyfora.pyAst.PyAstFreeVariableAnalyses
的用法示例。
在下文中一共展示了PyAstFreeVariableAnalyses.getFreeVariables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_freeVariables_globalStmt_2
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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)
示例2: test_freeVariables_function_context
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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))
示例3: test_freeVariables_CompsAndGenExp2
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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))
示例4: test_freeVariables_ListComp_4
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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))
示例5: test_freeVariables_ListComp_2
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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))
示例6: test_freeVariables_functionDef_2
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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))
示例7: test_freeVariables_Lambda_1
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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))
示例8: test_freeVariables_DictComp_2
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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))
示例9: test_freeVariables_Assign
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
def test_freeVariables_Assign(self):
tree = ast.parse(
textwrap.dedent(
"""
(x, y), z = w
"""
)
)
self.assertEqual(set(["w"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
示例10: test_freeVariables_classDef_1
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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))
示例11: test_freeVariables_SetComp_1
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
def test_freeVariables_SetComp_1(self):
tree = ast.parse(
textwrap.dedent(
"""
{v for x in q}
"""
)
)
self.assertEqual(set(["v", "q"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
示例12: test_freeVariables_DictComp_1
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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))
示例13: test_freeVariables_ListComp_3
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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))
示例14: test_freeVariables_For
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
def test_freeVariables_For(self):
tree = ast.parse(
textwrap.dedent(
"""
for x in elt:
x + 2
"""
)
)
self.assertEqual(set(["elt"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
示例15: test_call_and_then_member
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
def test_call_and_then_member(self):
tree = ast.parse(
textwrap.dedent(
"""
def f():
return g(1).__str__()
"""
)
)
self.assertEqual(set(["g"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))