Commit 94ed1b5a authored by Stefan Behnel's avatar Stefan Behnel

fix list comprehensions as if conditions

parent 5ef060ae
......@@ -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):
......
......@@ -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())
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment