transformations.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:ITAP-django 作者: krivers 项目源码 文件源码
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 ###
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号