Author: Amaury Forgeot d'Arc <[email protected]>
Branch:
Changeset: r60496:d4c30109a272
Date: 2013-01-24 00:32 +0100
http://bitbucket.org/pypy/pypy/changeset/d4c30109a272/
Log: Merge 25f5ab9 from py3k: annotation of range(): if start and step
are non-negative, then the item is non-negative as well.
Used in py3k function array._array_reconstructor, which uses a list
comprehension with a variable (positive) stride.
diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py
--- a/rpython/annotator/builtin.py
+++ b/rpython/annotator/builtin.py
@@ -79,7 +79,7 @@
s_item = s_ImpossibleValue
else:
nonneg = False # so far
- if step > 0:
+ if step > 0 or s_step.nonneg:
nonneg = s_start.nonneg
elif step < 0:
nonneg = s_stop.nonneg or (s_stop.is_constant() and
diff --git a/rpython/annotator/test/test_annrpython.py
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -2694,6 +2694,23 @@
assert isinstance(s, annmodel.SomeInteger)
assert s.nonneg
+ def test_range_nonneg_variablestep(self):
+ def get_step(n):
+ if n == 1:
+ return 2
+ else:
+ return 3
+ def fun(n, k):
+ step = get_step(n)
+ for i in range(0, n, step):
+ if k == 17:
+ return i
+ return 0
+ a = self.RPythonAnnotator()
+ s = a.build_types(fun, [int, int])
+ assert isinstance(s, annmodel.SomeInteger)
+ assert s.nonneg
+
def test_reverse_range_nonneg(self):
def fun(n, k):
for i in range(n-1, -1, -1):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit