本文整理匯總了Python中pyfora.PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains方法的典型用法代碼示例。如果您正苦於以下問題:Python PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains方法的具體用法?Python PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains怎麽用?Python PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyfora.PyAstFreeVariableAnalyses
的用法示例。
在下文中一共展示了PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_member_acces_after_possible_assignment
# 需要導入模塊: from pyfora import PyAstFreeVariableAnalyses [as 別名]
# 或者: from pyfora.PyAstFreeVariableAnalyses import getFreeVariableMemberAccessChains [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)
)
示例2: test_call_and_then_member_chain
# 需要導入模塊: from pyfora import PyAstFreeVariableAnalyses [as 別名]
# 或者: from pyfora.PyAstFreeVariableAnalyses import getFreeVariableMemberAccessChains [as 別名]
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)
)
示例3: test_freeVariablesMemberAccessChain_onFunctionDefNode
# 需要導入模塊: from pyfora import PyAstFreeVariableAnalyses [as 別名]
# 或者: from pyfora.PyAstFreeVariableAnalyses import getFreeVariableMemberAccessChains [as 別名]
def test_freeVariablesMemberAccessChain_onFunctionDefNode(self):
tree1 = ast.parse(
textwrap.dedent(
"""
def g(arg):
if arg < 0:
return x + arg
return x * h(arg - 1, g)
"""
)
)
res = PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains(tree1)
self.assertEqual(
set([('h',), ('x',)]),
res
)
tree2 = PyAstUtil.functionDefOrLambdaAtLineNumber(tree1, 2)
self.assertEqual(
set([('h',), ('x',)]),
PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains(tree2, False)
)
示例4: test_freeVariableMemberAccessChains_1
# 需要導入模塊: from pyfora import PyAstFreeVariableAnalyses [as 別名]
# 或者: from pyfora.PyAstFreeVariableAnalyses import getFreeVariableMemberAccessChains [as 別名]
def test_freeVariableMemberAccessChains_1(self):
tree = ast.parse(
textwrap.dedent(
"""
def f():
x
x = 2
def f(x):
x.y
z.w.q
"""
)
)
res = PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains(tree)
self.assertEqual(
set([('z', 'w', 'q')]),
res
)
示例5: _freeOrUninitializedMemberAccesChains
# 需要導入模塊: from pyfora import PyAstFreeVariableAnalyses [as 別名]
# 或者: from pyfora.PyAstFreeVariableAnalyses import getFreeVariableMemberAccessChains [as 別名]
def _freeOrUninitializedMemberAccesChains(self, pyAst):
# ATz: just added 'False' as a 2nd argument, but we may need to check
# that whenever pyAst is a FunctionDef node, its context is not a class
# (i.e., it is not an instance method). In that case, we need to pass
# 'True' as the 2nd argument.
freeVariableMemberAccessChains = \
PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains(
pyAst, isClassContext=False
)
possiblyUninitializedVariables = \
PyAstUninstantiatedVariablesAnalysis\
.collectPossiblyUninitializedLocalVariablesInScope(
pyAst
)
possiblyUninitializedVariablesAsChains = [
(val,) for val in possiblyUninitializedVariables]
return freeVariableMemberAccessChains.union(
possiblyUninitializedVariablesAsChains)
示例6: test_freeVariableMemberAccessChains_2
# 需要導入模塊: from pyfora import PyAstFreeVariableAnalyses [as 別名]
# 或者: from pyfora.PyAstFreeVariableAnalyses import getFreeVariableMemberAccessChains [as 別名]
def test_freeVariableMemberAccessChains_2(self):
tree = ast.parse(
textwrap.dedent(
"""
def f():
y = 2
class C:
def g(self, arg):
x.y.z + y + arg
x = 2
C.f
"""
)
)
res = PyAstFreeVariableAnalyses.getFreeVariableMemberAccessChains(tree)
self.assertEqual(
set([('C', 'f')]),
res
)