def gatherAllNames(a, keep_orig=True):
"""Gather all names in the tree (variable or otherwise).
Names are returned along with their original names
(which are used in variable mapping)"""
if type(a) == list:
allIds = set()
for line in a:
allIds |= gatherAllNames(line)
return allIds
if not isinstance(a, ast.AST):
return set()
allIds = set()
for node in ast.walk(a):
if type(node) == ast.Name:
origName = node.originalId if (keep_orig and hasattr(node, "originalId")) else None
allIds |= set([(node.id, origName)])
return allIds
评论列表
文章目录