[pypy-commit] pypy default: Make __builtin__.next RPython

alex_gaynor noreply at buildbot.pypy.org
Thu Aug 16 03:08:14 CEST 2012


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r56731:7a48df4c2691
Date: 2012-08-15 21:07 -0400
http://bitbucket.org/pypy/pypy/changeset/7a48df4c2691/

Log:	Make __builtin__.next RPython

diff --git a/pypy/annotation/test/test_annrpython.py b/pypy/annotation/test/test_annrpython.py
--- a/pypy/annotation/test/test_annrpython.py
+++ b/pypy/annotation/test/test_annrpython.py
@@ -3829,7 +3829,7 @@
 
             def next(self):
                 return 1
-        
+
         def fn():
             s = 0
             for x in A():
@@ -3841,6 +3841,16 @@
         assert len(a.translator.graphs) == 3 # fn, __iter__, next
         assert isinstance(s, annmodel.SomeInteger)
 
+    def test_next_function(self):
+        def fn(n):
+            x = [0, 1, n]
+            i = iter(x)
+            return next(i) + next(i)
+
+        a = self.RPythonAnnotator()
+        s = a.build_types(fn, [int])
+        assert isinstance(s, annmodel.SomeInteger)
+
     def test_no_attr_on_common_exception_classes(self):
         for cls in [ValueError, Exception]:
             def fn():
diff --git a/pypy/objspace/flow/operation.py b/pypy/objspace/flow/operation.py
--- a/pypy/objspace/flow/operation.py
+++ b/pypy/objspace/flow/operation.py
@@ -236,6 +236,7 @@
         name = line[0]
         if hasattr(operator, name):
             Table.append((name, getattr(operator, name)))
+    Table.append(('next', __builtin__.next))
     # build the dictionaries
     for name, func in Table:
         if name not in FunctionByName:
diff --git a/pypy/rpython/test/test_rbuiltin.py b/pypy/rpython/test/test_rbuiltin.py
--- a/pypy/rpython/test/test_rbuiltin.py
+++ b/pypy/rpython/test/test_rbuiltin.py
@@ -540,6 +540,26 @@
         res = self.interpret(llfn, [0x12345678])
         assert res == 0x5678
 
+    def test_builtin_next(self):
+        def f(n):
+            x = [1, n, 2]
+            s = iter(x)
+            return next(s) + next(s)
+        res = self.interpret(f, [10])
+        assert res == 11
+
+    def test_builtin_next_stop_iteration(self):
+        def f(n):
+            x = [n]
+            s = iter(x)
+            try:
+                return next(s) + next(s)
+            except StopIteration:
+                return n + 500
+
+        res = self.interpret(f, [12])
+        assert res == 512
+
 
 class TestLLtype(BaseTestRbuiltin, LLRtypeMixin):
 


More information about the pypy-commit mailing list