[pypy-commit] pypy py3.5: Raise ValueError instead of TypeError here.

mjacob pypy.commits at gmail.com
Thu Mar 2 15:49:17 EST 2017


Author: Manuel Jacob <me at manueljacob.de>
Branch: py3.5
Changeset: r90498:ce30e89d7f14
Date: 2017-03-02 21:48 +0100
http://bitbucket.org/pypy/pypy/changeset/ce30e89d7f14/

Log:	Raise ValueError instead of TypeError here.

diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -500,6 +500,7 @@
         assert u'x\ty'.expandtabs(-42) == u'xy'
 
     def test_translate(self):
+        import sys
         assert 'bbbc' == 'abababc'.translate({ord('a'):None})
         assert 'iiic' == 'abababc'.translate({ord('a'):None, ord('b'):ord('i')})
         assert 'iiix' == 'abababc'.translate({ord('a'):None, ord('b'):ord('i'), ord('c'):'x'})
@@ -511,6 +512,7 @@
         assert 'abababc'.translate({ord('a'): ''}) == 'bbbc'
 
         raises(TypeError, 'hello'.translate)
+        raises(ValueError, "\xff".translate, {0xff: sys.maxunicode+1})
 
     def test_maketrans(self):
         assert 'abababc' == 'abababc'.translate({'b': '<i>'})
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -429,7 +429,7 @@
                 elif space.isinstance_w(w_newval, space.w_int):
                     newval = space.int_w(w_newval)
                     if newval < 0 or newval > maxunicode:
-                        raise oefmt(space.w_TypeError,
+                        raise oefmt(space.w_ValueError,
                                     "character mapping must be in range(%s)",
                                     hex(maxunicode + 1))
                     result.append(unichr(newval))


More information about the pypy-commit mailing list