Skip to content

Commit 4d792e4

Browse files
committed
Use %T to format type names
1 parent a513ee8 commit 4d792e4

5 files changed

Lines changed: 24 additions & 31 deletions

File tree

Objects/abstract.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,17 +1418,16 @@ _PyNumber_Index(PyObject *item)
14181418

14191419
if (!PyLong_Check(result)) {
14201420
PyErr_Format(PyExc_TypeError,
1421-
"%.200s.__index__ returned non-int (type %.200s)",
1422-
Py_TYPE(item)->tp_name, Py_TYPE(result)->tp_name);
1421+
"%T.__index__ returned non-int (type %T)", item, result);
14231422
Py_DECREF(result);
14241423
return NULL;
14251424
}
14261425
/* Issue #17576: warn if 'result' not of exact type int. */
14271426
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
1428-
"%.200s.__index__ returned non-int (type %.200s). "
1427+
"%T.__index__ returned non-int (type %T). "
14291428
"The ability to return an instance of a strict subclass of int "
14301429
"is deprecated, and may be removed in a future version of Python.",
1431-
Py_TYPE(item)->tp_name, Py_TYPE(result)->tp_name)) {
1430+
item, result)) {
14321431
Py_DECREF(result);
14331432
return NULL;
14341433
}
@@ -1528,17 +1527,16 @@ PyNumber_Long(PyObject *o)
15281527

15291528
if (!PyLong_Check(result)) {
15301529
PyErr_Format(PyExc_TypeError,
1531-
"%.200s.__int__ returned non-int (type %.200s)",
1532-
Py_TYPE(o)->tp_name, Py_TYPE(result)->tp_name);
1530+
"%T.__int__ returned non-int (type %T)", o, result);
15331531
Py_DECREF(result);
15341532
return NULL;
15351533
}
15361534
/* Issue #17576: warn if 'result' not of exact type int. */
15371535
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
1538-
"%.200s.__int__ returned non-int (type %.200s). "
1536+
"%T.__int__ returned non-int (type %T). "
15391537
"The ability to return an instance of a strict subclass of int "
15401538
"is deprecated, and may be removed in a future version of Python.",
1541-
Py_TYPE(o)->tp_name, Py_TYPE(result)->tp_name)) {
1539+
o, result)) {
15421540
Py_DECREF(result);
15431541
return NULL;
15441542
}
@@ -1606,17 +1604,16 @@ PyNumber_Float(PyObject *o)
16061604

16071605
if (!PyFloat_Check(res)) {
16081606
PyErr_Format(PyExc_TypeError,
1609-
"%.50s.__float__ returned non-float (type %.50s)",
1610-
Py_TYPE(o)->tp_name, Py_TYPE(res)->tp_name);
1607+
"%T.__float__ returned non-float (type %T)", o, res);
16111608
Py_DECREF(res);
16121609
return NULL;
16131610
}
16141611
/* Issue #26983: warn if 'res' not of exact type float. */
16151612
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
1616-
"%.50s.__float__ returned non-float (type %.50s). "
1613+
"%T.__float__ returned non-float (type %T). "
16171614
"The ability to return an instance of a strict subclass of float "
16181615
"is deprecated, and may be removed in a future version of Python.",
1619-
Py_TYPE(o)->tp_name, Py_TYPE(res)->tp_name)) {
1616+
o, res)) {
16201617
Py_DECREF(res);
16211618
return NULL;
16221619
}
@@ -2815,9 +2812,8 @@ PyObject_GetIter(PyObject *o)
28152812
PyObject *res = (*f)(o);
28162813
if (res != NULL && !PyIter_Check(res)) {
28172814
PyErr_Format(PyExc_TypeError,
2818-
"%.100s.iter() returned non-iterator "
2819-
"of type '%.100s'",
2820-
Py_TYPE(o)->tp_name, Py_TYPE(res)->tp_name);
2815+
"%T.iter() returned non-iterator of type '%T'",
2816+
o, res);
28212817
Py_SETREF(res, NULL);
28222818
}
28232819
return res;

Objects/bytesobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ 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-
"%.200s.__bytes__ returned non-bytes (type %.200s)",
571-
Py_TYPE(v)->tp_name, Py_TYPE(result)->tp_name);
570+
"%T.__bytes__ returned non-bytes (type %T)",
571+
v, result);
572572
Py_DECREF(result);
573573
return NULL;
574574
}
@@ -2762,8 +2762,8 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
27622762
return NULL;
27632763
if (!PyBytes_Check(bytes)) {
27642764
PyErr_Format(PyExc_TypeError,
2765-
"%.200s.__bytes__ returned non-bytes (type %.200s)",
2766-
Py_TYPE(x)->tp_name, Py_TYPE(bytes)->tp_name);
2765+
"%T.__bytes__ returned non-bytes (type %T)",
2766+
x, bytes);
27672767
Py_DECREF(bytes);
27682768
return NULL;
27692769
}

Objects/complexobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,17 +499,17 @@ try_complex_special_method(PyObject *op)
499499
}
500500
if (!PyComplex_Check(res)) {
501501
PyErr_Format(PyExc_TypeError,
502-
"%.200s.__complex__ returned non-complex (type %.200s)",
503-
Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name);
502+
"%T.__complex__ returned non-complex (type %T)",
503+
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-
"%.200s.__complex__ returned non-complex (type %.200s). "
509+
"%T.__complex__ returned non-complex (type %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.",
512-
Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name)) {
512+
op, res)) {
513513
Py_DECREF(res);
514514
return NULL;
515515
}

Objects/object.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,7 @@ PyObject_Repr(PyObject *v)
779779
}
780780
if (!PyUnicode_Check(res)) {
781781
_PyErr_Format(tstate, PyExc_TypeError,
782-
"%.200s.__repr__ returned non-string (type %.200s)",
783-
Py_TYPE(v)->tp_name, Py_TYPE(res)->tp_name);
782+
"%T.__repr__ returned non-string (type %T)", v, res);
784783
Py_DECREF(res);
785784
return NULL;
786785
}
@@ -822,8 +821,7 @@ PyObject_Str(PyObject *v)
822821
}
823822
if (!PyUnicode_Check(res)) {
824823
_PyErr_Format(tstate, PyExc_TypeError,
825-
"%.200s.__str__ returned non-string (type %.200s)",
826-
Py_TYPE(v)->tp_name, Py_TYPE(res)->tp_name);
824+
"%T.__str__ returned non-string (type %T)", v, res);
827825
Py_DECREF(res);
828826
return NULL;
829827
}
@@ -878,8 +876,8 @@ PyObject_Bytes(PyObject *v)
878876
return NULL;
879877
if (!PyBytes_Check(result)) {
880878
PyErr_Format(PyExc_TypeError,
881-
"%.200s.__bytes__ returned non-bytes (type %.200s)",
882-
Py_TYPE(v)->tp_name, Py_TYPE(result)->tp_name);
879+
"%T.__bytes__ returned non-bytes (type %T)",
880+
v, result);
883881
Py_DECREF(result);
884882
return NULL;
885883
}

Objects/typeobject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9920,8 +9920,7 @@ slot_nb_bool(PyObject *self)
99209920
}
99219921
else {
99229922
PyErr_Format(PyExc_TypeError,
9923-
"%s.__bool__ returned non-bool (type %s)",
9924-
Py_TYPE(self)->tp_name, Py_TYPE(value)->tp_name);
9923+
"%T.__bool__ returned non-bool (type %T)", self, value);
99259924
result = -1;
99269925
}
99279926

0 commit comments

Comments
 (0)