def propogateNameMetadata(a, namesToKeep, imports):
"""Propogates name metadata through a state. We assume that the names are all properly formatted"""
if type(a) == list:
for child in a:
child = propogateNameMetadata(child, namesToKeep, imports)
return a
elif not isinstance(a, ast.AST):
return a
if type(a) == ast.Name:
if (builtInName(a.id) or importedName(a.id, imports)):
pass
elif a.id in namesToKeep:
a.dontChangeName = True
else:
if not hasattr(a, "originalId"):
a.originalId = a.id
if not isAnonVariable(a.id):
a.dontChangeName = True # it's a name we shouldn't mess with
elif type(a) == ast.arg:
if (builtInName(a.arg) or importedName(a.arg, imports)):
pass
elif a.arg in namesToKeep:
a.dontChangeName = True
else:
if not hasattr(a, "originalId"):
a.originalId = a.arg
if not isAnonVariable(a.arg):
a.dontChangeName = True # it's a name we shouldn't mess with
for child in ast.iter_child_nodes(a):
child = propogateNameMetadata(child, namesToKeep, imports)
return a
### HELPER FOLDING ###
评论列表
文章目录