]> granicus.if.org Git - python/commitdiff
Issue #13410: Fixed a bug in PyUnicode_Format where it failed to properly
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 10 Apr 2016 12:26:52 +0000 (15:26 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 10 Apr 2016 12:26:52 +0000 (15:26 +0300)
ignore errors from a __int__() method.

Patch based on the patch for issue #15516.

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

index ba3399ea251d77615551d88baa7384ec7344e88f..633601c1bf15e7ddaf80c3a2a9d06024bbaf6a85 100644 (file)
@@ -243,6 +243,7 @@ class FormatTest(unittest.TestCase):
 
         fst = IntFails()
         testformat("%x", fst, '0')
+        testformat(u"%x", fst, '0')
 
         # Test exception for unknown format characters
         if verbose:
index 7219c5e8094abe98a4dbafeed3fd53f96ff6bdaa..ed6e8bc449541e5f6d2f87b417484507b1c1746c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 2.7.12?
 Core and Builtins
 -----------------
 
+- Issue #13410: Fixed a bug in PyUnicode_Format where it failed to properly
+  ignore errors from a __int__() method.
+
 - Issue #26494: Fixed crash on iterating exhausting iterators.
   Affected classes are generic sequence iterators, iterators of bytearray,
   list, tuple, set, frozenset, dict, OrderedDict and corresponding views.
index 454451eb671cb5c793cd62b169fe37fbe0bdbb51..d06ce2cb97026078f1d0cd5b2d19fc53a29ad5c9 100644 (file)
@@ -8632,7 +8632,10 @@ PyObject *PyUnicode_Format(PyObject *format,
                     }
                     else {
                         iobj = PyNumber_Int(v);
-                        if (iobj==NULL) iobj = PyNumber_Long(v);
+                        if (iobj==NULL) {
+                            PyErr_Clear();
+                            iobj = PyNumber_Long(v);
+                        }
                     }
                     if (iobj!=NULL) {
                         if (PyInt_Check(iobj)) {