@@ -884,8 +884,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
884884
885885 if (result && !PyUnicode_Check (result )) {
886886 PyErr_Format (PyExc_TypeError ,
887- "__format__ must return a str, not %.200s" ,
888- Py_TYPE (result )-> tp_name );
887+ "__format__ must return type str (not %T)" , result );
889888 Py_SETREF (result , NULL );
890889 goto done ;
891890 }
@@ -1418,13 +1417,14 @@ _PyNumber_Index(PyObject *item)
14181417
14191418 if (!PyLong_Check (result )) {
14201419 PyErr_Format (PyExc_TypeError ,
1421- "%T.__index__ returned non-int (type %T)" , item , result );
1420+ "%T.__index__ must return type int (not %T)" ,
1421+ item , result );
14221422 Py_DECREF (result );
14231423 return NULL ;
14241424 }
14251425 /* Issue #17576: warn if 'result' not of exact type int. */
14261426 if (PyErr_WarnFormat (PyExc_DeprecationWarning , 1 ,
1427- "%T.__index__ returned non- int (type %T). "
1427+ "%T.__index__ must return type int (not %T). "
14281428 "The ability to return an instance of a strict subclass of int "
14291429 "is deprecated, and may be removed in a future version of Python." ,
14301430 item , result )) {
@@ -1527,13 +1527,14 @@ PyNumber_Long(PyObject *o)
15271527
15281528 if (!PyLong_Check (result )) {
15291529 PyErr_Format (PyExc_TypeError ,
1530- "%T.__int__ returned non-int (type %T)" , o , result );
1530+ "%T.__int__ must return type int (not %T)" ,
1531+ o , result );
15311532 Py_DECREF (result );
15321533 return NULL ;
15331534 }
15341535 /* Issue #17576: warn if 'result' not of exact type int. */
15351536 if (PyErr_WarnFormat (PyExc_DeprecationWarning , 1 ,
1536- "%T.__int__ returned non- int (type %T). "
1537+ "%T.__int__ must return type int (not %T). "
15371538 "The ability to return an instance of a strict subclass of int "
15381539 "is deprecated, and may be removed in a future version of Python." ,
15391540 o , result )) {
@@ -1604,13 +1605,13 @@ PyNumber_Float(PyObject *o)
16041605
16051606 if (!PyFloat_Check (res )) {
16061607 PyErr_Format (PyExc_TypeError ,
1607- "%T.__float__ returned non- float (type %T)" , o , res );
1608+ "%T.__float__ must return type float (not %T)" , o , res );
16081609 Py_DECREF (res );
16091610 return NULL ;
16101611 }
16111612 /* Issue #26983: warn if 'res' not of exact type float. */
16121613 if (PyErr_WarnFormat (PyExc_DeprecationWarning , 1 ,
1613- "%T.__float__ returned non- float (type %T). "
1614+ "%T.__float__ must return type float (not %T). "
16141615 "The ability to return an instance of a strict subclass of float "
16151616 "is deprecated, and may be removed in a future version of Python." ,
16161617 o , res )) {
@@ -2812,7 +2813,7 @@ PyObject_GetIter(PyObject *o)
28122813 PyObject * res = (* f )(o );
28132814 if (res != NULL && !PyIter_Check (res )) {
28142815 PyErr_Format (PyExc_TypeError ,
2815- "%T.iter() returned non- iterator of type '%T'" ,
2816+ "%T.iter() must return type iterator of type '%T'" ,
28162817 o , res );
28172818 Py_SETREF (res , NULL );
28182819 }
0 commit comments