lhs = UtilNodes.ResultRefNode(node.operand1)
conds = []
+ temps = []
for arg in args:
+ if not arg.is_simple():
+ # must evaluate all non-simple RHS before doing the comparisons
+ arg = UtilNodes.LetRefNode(arg)
+ temps.append(arg)
cond = ExprNodes.PrimaryCmpNode(
pos = node.pos,
operand1 = lhs,
operand2 = right)
condition = reduce(concat, conds)
- return UtilNodes.EvalWithTempExprNode(lhs, condition)
+ new_node = UtilNodes.EvalWithTempExprNode(lhs, condition)
+ for temp in temps[::-1]:
+ new_node = UtilNodes.EvalWithTempExprNode(temp, new_node)
+ return new_node
visit_Node = Visitor.VisitorTransform.recurse_to_children
--- /dev/null
+
+def count(i=[0]):
+ i[0] += 1
+ return i[0]
+
+def test(x):
+ """
+ >>> def py_count(i=[0]):
+ ... i[0] += 1
+ ... return i[0]
+ >>> 1 in (py_count(), py_count(), py_count(), py_count())
+ True
+ >>> 4 in (py_count(), py_count(), py_count(), py_count())
+ False
+ >>> 12 in (py_count(), py_count(), py_count(), py_count())
+ True
+
+ >>> test(1)
+ True
+ >>> test(4)
+ False
+ >>> test(12)
+ True
+ """
+ return x in (count(), count(), count(), count())