Commit f766a7fc authored by Stefan Behnel's avatar Stefan Behnel

work around reversed(range()) bug by disabling optimised looping for...

work around reversed(range()) bug by disabling optimised looping for non-trivial step values (ticket #763)
parent 24631a45
......@@ -560,6 +560,9 @@ class IterationTransform(Visitor.VisitorTransform):
if step_value == 0:
# will lead to an error elsewhere
return node
if reversed and step_value not in (1, -1):
# FIXME: currently broken - requires calculation of the correct bounds
return node
if not isinstance(step, ExprNodes.IntNode):
step = ExprNodes.IntNode(step_pos, value=str(step_value),
constant_result=step_value)
......
......@@ -133,6 +133,25 @@ def reversed_range_step_neg(int a, int b):
result.append(i)
return result, i
#@cython.test_assert_path_exists('//ForFromStatNode')
def reversed_range_step3(int a, int b):
"""
>>> [ i for i in _reversed(range(0, 5, 3)) ]
[3, 0]
>>> reversed_range_step3(0, 5)
([3, 0], 0)
>>> [ i for i in _reversed(range(5, 0, 3)) ]
[]
>>> reversed_range_step3(5, 0)
([], 99)
"""
cdef int i = 99
result = []
for i in reversed(range(a, b, 3)):
result.append(i)
return result, i
unicode_string = u"abcDEF"
@cython.test_assert_path_exists('//ForFromStatNode')
......
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