@@ -887,7 +887,8 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
887887
888888 if (result && !PyUnicode_Check (result )) {
889889 PyErr_Format (PyExc_TypeError ,
890- "__format__ must return type str (not %T)" , result );
890+ "%T.__format__() must return type str (not %T)" ,
891+ obj , result );
891892 Py_SETREF (result , NULL );
892893 goto done ;
893894 }
@@ -1420,14 +1421,14 @@ _PyNumber_Index(PyObject *item)
14201421
14211422 if (!PyLong_Check (result )) {
14221423 PyErr_Format (PyExc_TypeError ,
1423- "%T.__index__ must return type int (not %T)" ,
1424+ "%T.__index__() must return type int (not %T)" ,
14241425 item , result );
14251426 Py_DECREF (result );
14261427 return NULL ;
14271428 }
14281429 /* Issue #17576: warn if 'result' not of exact type int. */
14291430 if (PyErr_WarnFormat (PyExc_DeprecationWarning , 1 ,
1430- "%T.__index__ must return type int (not %T). "
1431+ "%T.__index__() must return type int (not %T). "
14311432 "The ability to return an instance of a strict subclass of int "
14321433 "is deprecated, and may be removed in a future version of Python." ,
14331434 item , result )) {
@@ -1530,14 +1531,14 @@ PyNumber_Long(PyObject *o)
15301531
15311532 if (!PyLong_Check (result )) {
15321533 PyErr_Format (PyExc_TypeError ,
1533- "%T.__int__ must return type int (not %T)" ,
1534+ "%T.__int__() must return type int (not %T)" ,
15341535 o , result );
15351536 Py_DECREF (result );
15361537 return NULL ;
15371538 }
15381539 /* Issue #17576: warn if 'result' not of exact type int. */
15391540 if (PyErr_WarnFormat (PyExc_DeprecationWarning , 1 ,
1540- "%T.__int__ must return type int (not %T). "
1541+ "%T.__int__() must return type int (not %T). "
15411542 "The ability to return an instance of a strict subclass of int "
15421543 "is deprecated, and may be removed in a future version of Python." ,
15431544 o , result )) {
@@ -1608,13 +1609,13 @@ PyNumber_Float(PyObject *o)
16081609
16091610 if (!PyFloat_Check (res )) {
16101611 PyErr_Format (PyExc_TypeError ,
1611- "%T.__float__ must return type float (not %T)" , o , res );
1612+ "%T.__float__() must return type float (not %T)" , o , res );
16121613 Py_DECREF (res );
16131614 return NULL ;
16141615 }
16151616 /* Issue #26983: warn if 'res' not of exact type float. */
16161617 if (PyErr_WarnFormat (PyExc_DeprecationWarning , 1 ,
1617- "%T.__float__ must return type float (not %T). "
1618+ "%T.__float__() must return type float (not %T). "
16181619 "The ability to return an instance of a strict subclass of float "
16191620 "is deprecated, and may be removed in a future version of Python." ,
16201621 o , res )) {
0 commit comments