本文整理汇总了Python中pyfora.PyAstFreeVariableAnalyses.getFreeVariables方法的典型用法代码示例。如果您正苦于以下问题:Python PyAstFreeVariableAnalyses.getFreeVariables方法的具体用法?Python PyAstFreeVariableAnalyses.getFreeVariables怎么用?Python PyAstFreeVariableAnalyses.getFreeVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyfora.PyAstFreeVariableAnalyses
的用法示例。
在下文中一共展示了PyAstFreeVariableAnalyses.getFreeVariables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_freeVariables_globalStmt_2
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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_member_acces_after_possible_assignment
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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)
)
示例3: test_freeVariables_DictComp_2
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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)
)
示例4: test_freeVariables_ListComp_4
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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_SetComp_1
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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)
)
示例6: test_freeVariables_ListComp_2
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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)
)
示例7: test_freeVariables_classDef_1
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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)
)
示例8: test_freeVariables_Lambda_1
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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)
)
示例9: test_freeVariables_Assign
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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_function_context
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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)
)
示例11: test_freeVariables_DictComp_1
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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)
)
示例12: test_freeVariables_functionDef_2
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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)
)
示例13: test_freeVariables_ListComp_3
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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_call_and_then_member
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.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)
)
示例15: test_freeVariables_functionCalls
# 需要导入模块: from pyfora import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.PyAstFreeVariableAnalyses import getFreeVariables [as 别名]
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)
)