Author: Philip Jenvey <[email protected]>
Branch: 
Changeset: r71354:3817c8108103
Date: 2014-05-06 16:56 -0700
http://bitbucket.org/pypy/pypy/changeset/3817c8108103/

Log:    customize index's error message to match cpython

diff --git a/pypy/module/operator/test/test_operator.py 
b/pypy/module/operator/test/test_operator.py
--- a/pypy/module/operator/test/test_operator.py
+++ b/pypy/module/operator/test/test_operator.py
@@ -195,4 +195,5 @@
         import operator
         assert operator.index(42) == 42
         assert operator.__index__(42) == 42
-        raises(TypeError, operator.index, "abc")
+        exc = raises(TypeError, operator.index, "abc")
+        assert str(exc.value) == "'str' object cannot be interpreted as an 
index"
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -794,13 +794,18 @@
     l = ["space.isinstance_w(w_result, %s)" % x
                 for x in checkerspec]
     checker = " or ".join(l)
+    if targetname == 'index':
+        msg = "'%%T' object cannot be interpreted as an index"
+    else:
+        msg = "unsupported operand type for %(targetname)s(): '%%T'"
+    msg = msg % locals()
     source = """if 1:
         def %(targetname)s(space, w_obj):
             w_impl = space.lookup(w_obj, %(specialname)r)
             if w_impl is None:
                 raise oefmt(space.w_TypeError,
-                            "unsupported operand type for %(targetname)s(): "
-                            "'%%T'", w_obj)
+                            %(msg)r,
+                            w_obj)
             w_result = space.get_and_call_function(w_impl, w_obj)
 
             if %(checker)s:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to