]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix closes issue12471 - wrong TypeError message when '%i' format spec was used.
authorSenthil Kumaran <senthil@uthcode.com>
Mon, 4 Jul 2011 04:03:16 +0000 (21:03 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Mon, 4 Jul 2011 04:03:16 +0000 (21:03 -0700)
Lib/test/test_unicode.py
Objects/unicodeobject.c

index 97be58793fee2da6506963afd604e6544f1bdf02..885e740b7663bb0ae3dcfd29d542e64064dfad1f 100644 (file)
@@ -788,6 +788,7 @@ class UnicodeTest(string_tests.CommonTest,
         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...')
index 7a70a5e917233e3dd386453179e6743943eb5e54..03807a45b9d1d03622489a51cd00a72eea2e6ac1 100644 (file)
@@ -9689,8 +9689,6 @@ PyObject *PyUnicode_Format(PyObject *format,
             case 'o':
             case 'x':
             case 'X':
-                if (c == 'i')
-                    c = 'd';
                 isnumok = 0;
                 if (PyNumber_Check(v)) {
                     PyObject *iobj=NULL;
@@ -9705,7 +9703,7 @@ PyObject *PyUnicode_Format(PyObject *format,
                     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;