本文整理匯總了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)
)