@@ -132,8 +132,9 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
132132 return defaultvalue ;
133133 }
134134 if (!PyLong_Check (result )) {
135- PyErr_Format (PyExc_TypeError , "__length_hint__ must be an integer, not %.100s" ,
136- Py_TYPE (result )-> tp_name );
135+ PyErr_Format (PyExc_TypeError ,
136+ "%T.__length_hint__() must return type int (not %T)" ,
137+ o , result );
137138 Py_DECREF (result );
138139 return -1 ;
139140 }
@@ -143,7 +144,8 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
143144 return -1 ;
144145 }
145146 if (res < 0 ) {
146- PyErr_Format (PyExc_ValueError , "__length_hint__() should return >= 0" );
147+ PyErr_Format (PyExc_ValueError ,
148+ "%T.__length_hint__() must return positive int" , o );
147149 return -1 ;
148150 }
149151 return res ;
@@ -2434,10 +2436,8 @@ method_output_as_list(PyObject *o, PyObject *meth)
24342436 PyThreadState * tstate = _PyThreadState_GET ();
24352437 if (_PyErr_ExceptionMatches (tstate , PyExc_TypeError )) {
24362438 _PyErr_Format (tstate , PyExc_TypeError ,
2437- "%.200s.%U() returned a non-iterable (type %.200s)" ,
2438- Py_TYPE (o )-> tp_name ,
2439- meth ,
2440- Py_TYPE (meth_output )-> tp_name );
2439+ "%T.%U() must return type iterable (not %T)" ,
2440+ o , meth , meth_output );
24412441 }
24422442 Py_DECREF (meth_output );
24432443 return NULL ;
@@ -2837,8 +2837,8 @@ PyObject_GetAIter(PyObject *o) {
28372837 PyObject * it = (* f )(o );
28382838 if (it != NULL && !PyAIter_Check (it )) {
28392839 PyErr_Format (PyExc_TypeError ,
2840- "aiter() returned not an async iterator of type '%.100s '" ,
2841- Py_TYPE ( it ) -> tp_name );
2840+ "%T. aiter() must return type async iterator of type '%T '" ,
2841+ o , it );
28422842 Py_SETREF (it , NULL );
28432843 }
28442844 return it ;
0 commit comments