本文整理汇总了Python中pyfora.pyAst.PyAstFreeVariableAnalyses.collectBoundValuesInScope方法的典型用法代码示例。如果您正苦于以下问题:Python PyAstFreeVariableAnalyses.collectBoundValuesInScope方法的具体用法?Python PyAstFreeVariableAnalyses.collectBoundValuesInScope怎么用?Python PyAstFreeVariableAnalyses.collectBoundValuesInScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyfora.pyAst.PyAstFreeVariableAnalyses
的用法示例。
在下文中一共展示了PyAstFreeVariableAnalyses.collectBoundValuesInScope方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _registerWithBlock
# 需要导入模块: from pyfora.pyAst import PyAstFreeVariableAnalyses [as 别名]
# 或者: from pyfora.pyAst.PyAstFreeVariableAnalyses import collectBoundValuesInScope [as 别名]
def _registerWithBlock(self, objectId, pyObject):
"""
`_registerWithBlock`: register a `PyforaWithBlock.PyforaWithBlock`
with `self.objectRegistry`.
Recursively call `walkPyObject` on the resolvable free variable
member access chains in the block and on the file object.
"""
lineNumber = pyObject.lineNumber
sourceTree = PyAstUtil.pyAstFromText(pyObject.sourceText)
withBlockAst = PyAstUtil.withBlockAtLineNumber(sourceTree, lineNumber)
withBlockFun = ast.FunctionDef(
name="",
args=ast.arguments(args=[], defaults=[], kwarg=None, vararg=None),
body=withBlockAst.body,
decorator_list=[],
lineno=lineNumber,
col_offset=0
)
if PyAstUtil.hasReturnInOuterScope(withBlockFun):
raise Exceptions.BadWithBlockError(
"return statement not supported in pyfora with-block (line %s)" %
PyAstUtil.getReturnLocationsInOuterScope(withBlockFun)[0])
if PyAstUtil.hasYieldInOuterScope(withBlockFun):
raise Exceptions.BadWithBlockError(
"yield expression not supported in pyfora with-block (line %s)" %
PyAstUtil.getYieldLocationsInOuterScope(withBlockFun)[0])
freeVariableMemberAccessChainsWithPositions = \
self._freeMemberAccessChainsWithPositions(withBlockFun)
boundValuesInScopeWithPositions = \
PyAstFreeVariableAnalyses.collectBoundValuesInScope(
withBlockFun, getPositions=True)
for boundValueWithPosition in boundValuesInScopeWithPositions:
val, pos = boundValueWithPosition
if val not in pyObject.unboundLocals and val in pyObject.boundVariables:
freeVariableMemberAccessChainsWithPositions.add(
PyAstFreeVariableAnalyses.VarWithPosition(var=(val,), pos=pos)
)
try:
freeVariableMemberAccessChainResolutions = \
self._resolveFreeVariableMemberAccessChains(
freeVariableMemberAccessChainsWithPositions, pyObject.boundVariables
)
except UnresolvedFreeVariableException as e:
_convertUnresolvedFreeVariableExceptionAndRaise(e, pyObject.sourceFileName)
try:
processedFreeVariableMemberAccessChainResolutions = {}
for chain, (resolution, position) in \
freeVariableMemberAccessChainResolutions.iteritems():
processedFreeVariableMemberAccessChainResolutions['.'.join(chain)] = \
self.walkPyObject(resolution)
except UnresolvedFreeVariableExceptionWithTrace as e:
e.addToTrace(
Exceptions.makeTraceElement(
path=pyObject.sourceFileName,
lineNumber=position.lineno
)
)
raise
sourceFileId = self.walkPyObject(
_FileDescription.cachedFromArgs(
fileName=pyObject.sourceFileName
)
)
self._objectRegistry.defineWithBlock(
objectId=objectId,
freeVariableMemberAccessChainsToId=\
processedFreeVariableMemberAccessChainResolutions,
sourceFileId=sourceFileId,
lineNumber=lineNumber
)