[Python-checkins] cpython (3.2): Fix closes issue12471 - wrong TypeError message when '%i' format spec was used.
senthil.kumaran
python-checkins at python.org
Mon Jul 4 06:05:36 CEST 2011
http://hg.python.org/cpython/rev/97707459bb5a
changeset: 71181:97707459bb5a
branch: 3.2
parent: 71178:f0382acebfe6
user: Senthil Kumaran <senthil at uthcode.com>
date: Sun Jul 03 21:03:16 2011 -0700
summary:
Fix closes issue12471 - wrong TypeError message when '%i' format spec was used.
files:
Lib/test/test_unicode.py | 1 +
Objects/unicodeobject.c | 4 +---
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -788,6 +788,7 @@
self.assertEqual('%c' % '\U00021483', '\U00021483')
self.assertRaises(TypeError, "%c".__mod__, "aa")
self.assertRaises(ValueError, "%.1\u1032f".__mod__, (1.0/3))
+ self.assertRaises(TypeError, "%i".__mod__, "aa")
# formatting jobs delegated from the string implementation:
self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...')
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9689,8 +9689,6 @@
case 'o':
case 'x':
case 'X':
- if (c == 'i')
- c = 'd';
isnumok = 0;
if (PyNumber_Check(v)) {
PyObject *iobj=NULL;
@@ -9705,7 +9703,7 @@
if (iobj!=NULL) {
if (PyLong_Check(iobj)) {
isnumok = 1;
- temp = formatlong(iobj, flags, prec, c);
+ temp = formatlong(iobj, flags, prec, (c == 'i'? 'd': c));
Py_DECREF(iobj);
if (!temp)
goto onError;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list