From: Stefan Behnel Date: Fri, 19 Dec 2008 01:18:27 +0000 (+0100) Subject: fix for-from loop in list comprehensions X-Git-Tag: 0.11-beta~112 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9de47b5e00526e593a1c97e01f15839a68115cf6;p=cython.git fix for-from loop in list comprehensions --- diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 0de8104f..9e383806 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -625,8 +625,12 @@ class ComprehensionTransform(VisitorTransform): # replace name references in the loop code by their temp node self.visitchildren(node, ['loop']) - self.comprehension_targets = outer_comprehension_targets + loop = node.loop + if type(loop) is Nodes.ForFromStatNode and loop.target.type.is_numeric: + loop.loopvar_node = loop.target + node.loop = TempsBlockNode(node.pos, body=node.loop, temps=temps) + self.comprehension_targets = outer_comprehension_targets return node def visit_NameNode(self, node): diff --git a/tests/run/forfrom.pyx b/tests/run/forfrom.pyx new file mode 100644 index 00000000..1135bb42 --- /dev/null +++ b/tests/run/forfrom.pyx @@ -0,0 +1,19 @@ +u""" +>>> for_else() +30 +>>> print( u'*'.join(int_comp()) ) +00*01*02 +""" + +def for_else(): + cdef int i, j=0, k=2 + for i from 0 <= i < 10: + j += k + else: + k = j+10 + return k + +def int_comp(): + cdef int i + return tuple([ u"%02d" % i + for i from 0 <= i < 3 ])