From: Stefan Behnel Date: Mon, 15 Nov 2010 09:28:15 +0000 (+0100) Subject: fix list comprehensions as if conditions X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=94ed1b5a3ad59be0af1f5bfc248cdffbf97862f4;p=cython.git fix list comprehensions as if conditions --- 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