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
评论列表
文章目录