From 94ed1b5a3ad59be0af1f5bfc248cdffbf97862f4 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Mon, 15 Nov 2010 10:28:15 +0100 Subject: [PATCH] fix list comprehensions as if conditions --- Cython/Compiler/Nodes.py | 1 - tests/run/cython3.pyx | 13 +++++++++++++ tests/run/listcomp.pyx | 13 +++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 6556d9e2..b077e250 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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): diff --git a/tests/run/cython3.pyx b/tests/run/cython3.pyx index 56594bd8..04a569bb 100644 --- a/tests/run/cython3.pyx +++ b/tests/run/cython3.pyx @@ -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()) diff --git a/tests/run/listcomp.pyx b/tests/run/listcomp.pyx index 1d9a38f6..81383061 100644 --- a/tests/run/listcomp.pyx +++ b/tests/run/listcomp.pyx @@ -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 -- 2.26.2