summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-04-10 12:26:52 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-04-10 12:26:52 (GMT)
commit149d080871f9bef276a3d4fa251ba6fbc910f770 (patch)
treea798ef6ce506f98339307b244450fe1a48c70866
parentf1669a390d262bf138cd8dc954443fb0e3c8c85e (diff)
downloadcpython-149d080871f9bef276a3d4fa251ba6fbc910f770.zip
cpython-149d080871f9bef276a3d4fa251ba6fbc910f770.tar.gz
cpython-149d080871f9bef276a3d4fa251ba6fbc910f770.tar.bz2
Issue #13410: Fixed a bug in PyUnicode_Format where it failed to properly
ignore errors from a __int__() method. Patch based on the patch for issue #15516.
-rw-r--r--Lib/test/test_format.py1
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/unicodeobject.c5
3 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py
index ba3399e..633601c 100644
--- a/Lib/test/test_format.py
+++ b/Lib/test/test_format.py
@@ -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:
diff --git a/Misc/NEWS b/Misc/NEWS
index 7219c5e..ed6e8bc 100644
--- 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.
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 454451e..d06ce2c 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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)) {