[pypy-commit] pypy default: Fix the PySequence_Index() error case.

amauryfa noreply at buildbot.pypy.org
Fri May 13 20:39:34 CEST 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r44150:9f22a5194041
Date: 2011-05-13 20:47 +0200
http://bitbucket.org/pypy/pypy/changeset/9f22a5194041/

Log:	Fix the PySequence_Index() error case. the C function should return
	-1 iff an exception is raised.

diff --git a/pypy/module/cpyext/sequence.py b/pypy/module/cpyext/sequence.py
--- a/pypy/module/cpyext/sequence.py
+++ b/pypy/module/cpyext/sequence.py
@@ -186,4 +186,5 @@
             return idx
         idx += 1
 
-    return -1
+    raise OperationError(space.w_ValueError, space.wrap(
+        "sequence.index(x): x not in sequence"))
diff --git a/pypy/module/cpyext/test/test_sequence.py b/pypy/module/cpyext/test/test_sequence.py
--- a/pypy/module/cpyext/test/test_sequence.py
+++ b/pypy/module/cpyext/test/test_sequence.py
@@ -129,6 +129,8 @@
         w_tofind = space.wrap(9001)
         result = api.PySequence_Index(w_l, w_tofind)
         assert result == -1
+        assert api.PyErr_Occurred() is space.w_ValueError
+        api.PyErr_Clear()
 
         gen = (x ** 2 for x in range(40))
         w_tofind = space.wrap(16)


More information about the pypy-commit mailing list