]> granicus.if.org Git - python/commitdiff
Change formatchar(), so that u"%c" % 0xffffffff now raises
authorWalter Dörwald <walter@livinglogic.de>
Wed, 2 Apr 2003 16:37:24 +0000 (16:37 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Wed, 2 Apr 2003 16:37:24 +0000 (16:37 +0000)
an OverflowError instead of a TypeError to be consistent
with "%c" % 256. See SF patch #710127.

Lib/test/test_unicode.py
Misc/NEWS
Objects/unicodeobject.c

index 2f19c515d3d6d8796764800ce78e4a7815d54866..28837b4364c3565177b652345f871b3398c86f62 100644 (file)
@@ -360,7 +360,7 @@ class UnicodeTest(
         self.assertEqual(u"%(x)s, %(\xfc)s" % {'x':u"abc", u'\xfc':"def"}, u'abc, def')
 
         self.assertEqual(u'%c' % 0x1234, u'\u1234')
-        self.assertRaises(ValueError, u"%c".__mod__, (sys.maxunicode+1,))
+        self.assertRaises(OverflowError, u"%c".__mod__, (sys.maxunicode+1,))
 
         # formatting jobs delegated from the string implementation:
         self.assertEqual('...%(foo)s...' % {'foo':u"abc"}, u'...abc...')
index fb829b9f3daac511c58e8d71e364a832570d65a1..673af1c4754e504295d7d08dcb99a4f4c07fde6c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -35,7 +35,8 @@ Core and builtins
   interpreter executions, would fail.
 
 - "%c" % u"a" now returns a unicode string instead of raising a
-  TypeError. See SF patch #710127.
+  TypeError. u"%c" % 0xffffffff now raises a OverflowError instead
+  of a TypeError to be consistent with "%c" % 256. See SF patch #710127.
 
 Extension modules
 -----------------
index dcfde347c3dce17507a39aa790ddb9c4deda30d4..b167a1d723a88eca732cbbcedadbafea064981be 100644 (file)
@@ -6157,14 +6157,14 @@ formatchar(Py_UNICODE *buf,
            goto onError;
 #ifdef Py_UNICODE_WIDE
        if (x < 0 || x > 0x10ffff) {
-           PyErr_SetString(PyExc_ValueError,
+           PyErr_SetString(PyExc_OverflowError,
                            "%c arg not in range(0x110000) "
                            "(wide Python build)");
            return -1;
        }
 #else
        if (x < 0 || x > 0xffff) {
-           PyErr_SetString(PyExc_ValueError,
+           PyErr_SetString(PyExc_OverflowError,
                            "%c arg not in range(0x10000) "
                            "(narrow Python build)");
            return -1;