From 1c5fd0c9122f6e0fe191d484fa5ff3ec149a636c Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 27 Mar 2010 07:52:54 +0100 Subject: [PATCH] apply flatten-in-list transform also to literal sets --- Cython/Compiler/Optimize.py | 4 +++- tests/run/inop.pyx | 26 +++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index 0efb23f1..c6e65bfa 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -591,7 +591,9 @@ class FlattenInListTransform(Visitor.VisitorTransform, SkipDeclarations): else: return node - if not isinstance(node.operand2, (ExprNodes.TupleNode, ExprNodes.ListNode)): + if not isinstance(node.operand2, (ExprNodes.TupleNode, + ExprNodes.ListNode, + ExprNodes.SetNode)): return node args = node.operand2.args diff --git a/tests/run/inop.pyx b/tests/run/inop.pyx index df5f2aeb..e836f4cc 100644 --- a/tests/run/inop.pyx +++ b/tests/run/inop.pyx @@ -52,16 +52,36 @@ def k(a): cdef int result = a in [1,2,3,4] return result -def m(int a): +def m_list(int a): """ - >>> m(2) + >>> m_list(2) 1 - >>> m(5) + >>> m_list(5) 0 """ cdef int result = a in [1,2,3,4] return result +def m_tuple(int a): + """ + >>> m_tuple(2) + 1 + >>> m_tuple(5) + 0 + """ + cdef int result = a in (1,2,3,4) + return result + +def m_set(int a): + """ + >>> m_set(2) + 1 + >>> m_set(5) + 0 + """ + cdef int result = a in {1,2,3,4} + return result + def n(a): """ >>> n('d *') -- 2.26.2