mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Change formatchar(), so that u"%c" % 0xffffffff now raises
an OverflowError instead of a TypeError to be consistent with "%c" % 256. See SF patch #710127.
This commit is contained in:
parent
7ba256f039
commit
44f527fea4
3 changed files with 5 additions and 4 deletions
|
@ -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"%(x)s, %(\xfc)s" % {'x':u"abc", u'\xfc':"def"}, u'abc, def')
|
||||||
|
|
||||||
self.assertEqual(u'%c' % 0x1234, u'\u1234')
|
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:
|
# formatting jobs delegated from the string implementation:
|
||||||
self.assertEqual('...%(foo)s...' % {'foo':u"abc"}, u'...abc...')
|
self.assertEqual('...%(foo)s...' % {'foo':u"abc"}, u'...abc...')
|
||||||
|
|
|
@ -35,7 +35,8 @@ Core and builtins
|
||||||
interpreter executions, would fail.
|
interpreter executions, would fail.
|
||||||
|
|
||||||
- "%c" % u"a" now returns a unicode string instead of raising a
|
- "%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
|
Extension modules
|
||||||
-----------------
|
-----------------
|
||||||
|
|
|
@ -6157,14 +6157,14 @@ formatchar(Py_UNICODE *buf,
|
||||||
goto onError;
|
goto onError;
|
||||||
#ifdef Py_UNICODE_WIDE
|
#ifdef Py_UNICODE_WIDE
|
||||||
if (x < 0 || x > 0x10ffff) {
|
if (x < 0 || x > 0x10ffff) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"%c arg not in range(0x110000) "
|
"%c arg not in range(0x110000) "
|
||||||
"(wide Python build)");
|
"(wide Python build)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (x < 0 || x > 0xffff) {
|
if (x < 0 || x > 0xffff) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"%c arg not in range(0x10000) "
|
"%c arg not in range(0x10000) "
|
||||||
"(narrow Python build)");
|
"(narrow Python build)");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue