fix list comprehensions as if conditions
authorStefan Behnel <scoder@users.berlios.de>
Mon, 15 Nov 2010 09:28:15 +0000 (10:28 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Mon, 15 Nov 2010 09:28:15 +0000 (10:28 +0100)
Cython/Compiler/Nodes.py
tests/run/cython3.pyx
tests/run/listcomp.pyx

index 6556d9e2279cdbb32e63e8f6456660c126a33821..b077e25030d331bdf5dd2e1dbbb616cc1a3e7945 100644 (file)
@@ -4035,7 +4035,6 @@ class IfClauseNode(Node):
         self.body.analyse_control_flow(env)
         
     def analyse_declarations(self, env):
-        self.condition.analyse_declarations(env)
         self.body.analyse_declarations(env)
     
     def analyse_expressions(self, env):
index 56594bd8d1bca1a47b7d44b25b4c7803bfe942f9..04a569bbb1cb0907025ed0206ae94250af06e931 100644 (file)
@@ -64,6 +64,19 @@ def list_comp_unknown_type(l):
     """
     return [x*2 for x in l if x % 2 == 0]
 
+def listcomp_as_condition(sequence):
+    """
+    >>> listcomp_as_condition(['a', 'b', '+'])
+    True
+    >>> listcomp_as_condition('ab+')
+    True
+    >>> listcomp_as_condition('abc')
+    False
+    """
+    if [1 for c in sequence if c in '+-*/<=>!%&|([^~,']:
+        return True
+    return False
+
 def set_comp():
     """
     >>> sorted(set_comp())
index 1d9a38f686ef4249cf9d6302a7b50c4c116c5af3..81383061e5218db1d49f22e7b671398a17dd20ad 100644 (file)
@@ -63,3 +63,16 @@ def nested_result():
     """
     result = [[a-1 for a in range(b)] for b in range(4)]
     return result
+
+def listcomp_as_condition(sequence):
+    """
+    >>> listcomp_as_condition(['a', 'b', '+'])
+    True
+    >>> listcomp_as_condition('ab+')
+    True
+    >>> listcomp_as_condition('abc')
+    False
+    """
+    if [1 for c in sequence if c in '+-*/<=>!%&|([^~,']:
+        return True
+    return False