本文整理汇总了Python中pyfora.pyAst.PyAstFreeVariableAnalyses类的典型用法代码示例。如果您正苦于以下问题:Python PyAstFreeVariableAnalyses类的具体用法?Python PyAstFreeVariableAnalyses怎么用?Python PyAstFreeVariableAnalyses使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PyAstFreeVariableAnalyses类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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:vishnur,项目名称:ufora,代码行数:12,代码来源:PyAstFreeVariableAnalyses_test.py
示例2: test_freeVariables_CompsAndGenExp2
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))
开发者ID:vishnur,项目名称:ufora,代码行数:28,代码来源:PyAstFreeVariableAnalyses_test.py
示例3: 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:vishnur,项目名称:ufora,代码行数:16,代码来源:PyAstFreeVariableAnalyses_test.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:Sandy4321,项目名称:ufora,代码行数:8,代码来源:PyAstFreeVariableAnalyses_test.py
示例5: 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:Sandy4321,项目名称:ufora,代码行数:9,代码来源:PyAstFreeVariableAnalyses_test.py
示例6: 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:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py
示例7: 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:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py
示例8: 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:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py
示例9: 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:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py
示例10: 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:vishnur,项目名称:ufora,代码行数:10,代码来源: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:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py
示例12: 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:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py
示例13: 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:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py
示例14: 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:vishnur,项目名称:ufora,代码行数:10,代码来源:PyAstFreeVariableAnalyses_test.py
示例15: 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:vishnur,项目名称:ufora,代码行数:11,代码来源:PyAstFreeVariableAnalyses_test.py
示例16: 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:vishnur,项目名称:ufora,代码行数:11,代码来源:PyAstFreeVariableAnalyses_test.py
示例17: test_freeVariables_For
def test_freeVariables_For(self):
tree = ast.parse(
textwrap.dedent(
"""
for x in elt:
x + 2
"""
)
)
self.assertEqual(set(["elt"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:11,代码来源:PyAstFreeVariableAnalyses_test.py
示例18: 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:vishnur,项目名称:ufora,代码行数:11,代码来源:PyAstFreeVariableAnalyses_test.py
示例19: test_call_and_then_member_chain
def test_call_and_then_member_chain(self):
tree = ast.parse(
textwrap.dedent(
"""
def f():
return g(1).__str__()
"""
)
)
self.assertEqual(set([("g",)]), PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:11,代码来源:PyAstFreeVariableAnalyses_test.py
示例20: test_freeVariables_classLocalVar_1
def test_freeVariables_classLocalVar_1(self):
tree = ast.parse(
textwrap.dedent(
"""
class C(object):
x = 0
"""
)
)
self.assertEqual(set(["object"]), PyAstFreeVariableAnalyses.getFreeVariables(tree))
开发者ID:vishnur,项目名称:ufora,代码行数:11,代码来源:PyAstFreeVariableAnalyses_test.py
注:本文中的pyfora.pyAst.PyAstFreeVariableAnalyses类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论