diff -r 16c4137a413c Lib/test/test_format.py --- a/Lib/test/test_format.py Wed Oct 05 22:34:51 2011 +0200 +++ b/Lib/test/test_format.py Wed Nov 16 00:46:07 2011 +0100 @@ -289,6 +289,17 @@ else: raise TestFailed, '"%*d"%(maxsize, -127) should fail' + def test_issue13410(self): + class Foo(object): + def __init__(self, x): + self.x = x + def __long__(self): + return long(self.x) + def __float__(self): + return float(self.x) + print '%d' % Foo(22) + + def test_main(): test_support.run_unittest(FormatTest) diff -r 16c4137a413c Objects/stringobject.c --- a/Objects/stringobject.c Wed Oct 05 22:34:51 2011 +0200 +++ b/Objects/stringobject.c Wed Nov 16 00:46:07 2011 +0100 @@ -4476,7 +4476,10 @@ } 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)) {