Skip to content

Commit 70d57c2

Browse files
committed
Use new message template
1 parent d811b4c commit 70d57c2

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

Objects/abstract.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Objects/bytesobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen)
567567
return NULL;
568568
if (!PyBytes_Check(result)) {
569569
PyErr_Format(PyExc_TypeError,
570-
"%T.__bytes__ returned non-bytes (type %T)",
570+
"%T.__bytes__ must return type bytes (not %T)",
571571
v, result);
572572
Py_DECREF(result);
573573
return NULL;
@@ -2762,7 +2762,7 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
27622762
return NULL;
27632763
if (!PyBytes_Check(bytes)) {
27642764
PyErr_Format(PyExc_TypeError,
2765-
"%T.__bytes__ returned non-bytes (type %T)",
2765+
"%T.__bytes__ must return type bytes (not %T)",
27662766
x, bytes);
27672767
Py_DECREF(bytes);
27682768
return NULL;

Objects/complexobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,14 @@ try_complex_special_method(PyObject *op)
499499
}
500500
if (!PyComplex_Check(res)) {
501501
PyErr_Format(PyExc_TypeError,
502-
"%T.__complex__ returned non-complex (type %T)",
502+
"%T.__complex__ must return type complex (not %T)",
503503
op, res);
504504
Py_DECREF(res);
505505
return NULL;
506506
}
507507
/* Issue #29894: warn if 'res' not of exact type complex. */
508508
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
509-
"%T.__complex__ returned non-complex (type %T). "
509+
"%T.__complex__ must return type complex (not %T). "
510510
"The ability to return an instance of a strict subclass of complex "
511511
"is deprecated, and may be removed in a future version of Python.",
512512
op, res)) {

Objects/object.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ PyObject_Repr(PyObject *v)
779779
}
780780
if (!PyUnicode_Check(res)) {
781781
_PyErr_Format(tstate, PyExc_TypeError,
782-
"%T.__repr__ returned non-string (type %T)", v, res);
782+
"%T.__repr__ must return type str (not %T)", v, res);
783783
Py_DECREF(res);
784784
return NULL;
785785
}
@@ -821,7 +821,7 @@ PyObject_Str(PyObject *v)
821821
}
822822
if (!PyUnicode_Check(res)) {
823823
_PyErr_Format(tstate, PyExc_TypeError,
824-
"%T.__str__ returned non-string (type %T)", v, res);
824+
"%T.__str__ must return type str (not %T)", v, res);
825825
Py_DECREF(res);
826826
return NULL;
827827
}
@@ -876,7 +876,7 @@ PyObject_Bytes(PyObject *v)
876876
return NULL;
877877
if (!PyBytes_Check(result)) {
878878
PyErr_Format(PyExc_TypeError,
879-
"%T.__bytes__ returned non-bytes (type %T)",
879+
"%T.__bytes__ must return type bytes (not %T)",
880880
v, result);
881881
Py_DECREF(result);
882882
return NULL;

Objects/typeobject.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,8 +2010,9 @@ type_get_annotations(PyObject *tp, void *Py_UNUSED(closure))
20102010
return NULL;
20112011
}
20122012
if (!PyDict_Check(annotations)) {
2013-
PyErr_Format(PyExc_TypeError, "__annotate__ returned non-dict of type '%.100s'",
2014-
Py_TYPE(annotations)->tp_name);
2013+
PyErr_Format(PyExc_TypeError,
2014+
"__annotate__ must return type dict of type '%T'",
2015+
annotations);
20152016
Py_DECREF(annotations);
20162017
Py_DECREF(annotate);
20172018
Py_DECREF(dict);
@@ -9920,7 +9921,8 @@ slot_nb_bool(PyObject *self)
99209921
}
99219922
else {
99229923
PyErr_Format(PyExc_TypeError,
9923-
"%T.__bool__ returned non-bool (type %T)", self, value);
9924+
"%T.__bool__ must return type bool (not %T)",
9925+
self, value);
99249926
result = -1;
99259927
}
99269928

0 commit comments

Comments
 (0)