Skip to content

Commit 7de8ea7

Browse files
wsfultonvstinner
andauthored
pythongh-136300: Modify C tests to conform to PEP-737 (pythonGH-136301)
- Use %T format specifier instead of %s and Py_TYPE(x)->tp_name. - Remove legacy %.200s format specifier for truncating type names. Co-authored-by: Victor Stinner <[email protected]>
1 parent 3343fce commit 7de8ea7

File tree

5 files changed

+5
-9
lines changed

5 files changed

+5
-9
lines changed

Modules/_testbuffer.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,8 +1855,7 @@ ndarray_subscript(PyObject *op, PyObject *key)
18551855

18561856
type_error:
18571857
PyErr_Format(PyExc_TypeError,
1858-
"cannot index memory using \"%.200s\"",
1859-
Py_TYPE(key)->tp_name);
1858+
"cannot index memory using \"%T\"", key);
18601859
err_occurred:
18611860
Py_DECREF(nd);
18621861
return NULL;

Modules/_testcapi/monitoring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static PyTypeObject PyCodeLike_Type = {
109109
};
110110

111111
#define RAISE_UNLESS_CODELIKE(v) if (!Py_IS_TYPE((v), &PyCodeLike_Type)) { \
112-
PyErr_Format(PyExc_TypeError, "expected a code-like, got %s", Py_TYPE(v)->tp_name); \
112+
PyErr_Format(PyExc_TypeError, "expected a code-like, got %T", v); \
113113
return NULL; \
114114
}
115115

Modules/_testcapi/time.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ static int
55
pytime_from_nanoseconds(PyTime_t *tp, PyObject *obj)
66
{
77
if (!PyLong_Check(obj)) {
8-
PyErr_Format(PyExc_TypeError, "expect int, got %s",
9-
Py_TYPE(obj)->tp_name);
8+
PyErr_Format(PyExc_TypeError, "expect int, got %T", obj);
109
return -1;
1110
}
1211

Modules/_testcapimodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,7 @@ test_thread_state(PyObject *self, PyObject *args)
515515
return NULL;
516516

517517
if (!PyCallable_Check(fn)) {
518-
PyErr_Format(PyExc_TypeError, "'%s' object is not callable",
519-
Py_TYPE(fn)->tp_name);
518+
PyErr_Format(PyExc_TypeError, "'%T' object is not callable", fn);
520519
return NULL;
521520
}
522521

Modules/_testinternalcapi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,8 +2207,7 @@ get_code(PyObject *obj)
22072207
return (PyCodeObject *)PyFunction_GetCode(obj);
22082208
}
22092209
return (PyCodeObject *)PyErr_Format(
2210-
PyExc_TypeError, "expected function or code object, got %s",
2211-
Py_TYPE(obj)->tp_name);
2210+
PyExc_TypeError, "expected function or code object, got %T", obj);
22122211
}
22132212

22142213
static PyObject *

0 commit comments

Comments
 (0)