transformations.py 文件源码

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

项目:ITAP-django 作者: krivers 项目源码 文件源码
def simplify_multicomp(a):
    if type(a) == ast.Compare and len(a.ops) > 1:
        # Only do one comparator at a time. If we don't do this, things get messy!
        comps = [a.left] + a.comparators
        values = [ ]
        # Compare each of the pairs
        for i in range(len(a.ops)):
            if i > 0:
                # Label all nodes as middle parts so we can recognize them later
                assignPropertyToAll(comps[i], "multiCompMiddle")
            values.append(ast.Compare(comps[i], [a.ops[i]], [deepcopy(comps[i+1])], multiCompPart=True))
        # Combine comparisons with and operators
        boolOp = ast.And(multiCompOp=True)
        boolopVal = ast.BoolOp(boolOp, values, multiComp=True, global_id=a.global_id)
        return boolopVal
    return a
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号