gh-136300: Modify C tests to conform to PEP-737 (GH-136301)
Some checks are pending
Tests / (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Undefined behavior sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run

- 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 <vstinner@python.org>
This commit is contained in:
William S Fulton 2025-07-11 14:18:35 +01:00 committed by GitHub
parent 3343fce05a
commit 7de8ea7be6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 5 additions and 9 deletions

View file

@ -1855,8 +1855,7 @@ ndarray_subscript(PyObject *op, PyObject *key)
type_error:
PyErr_Format(PyExc_TypeError,
"cannot index memory using \"%.200s\"",
Py_TYPE(key)->tp_name);
"cannot index memory using \"%T\"", key);
err_occurred:
Py_DECREF(nd);
return NULL;

View file

@ -109,7 +109,7 @@ static PyTypeObject PyCodeLike_Type = {
};
#define RAISE_UNLESS_CODELIKE(v) if (!Py_IS_TYPE((v), &PyCodeLike_Type)) { \
PyErr_Format(PyExc_TypeError, "expected a code-like, got %s", Py_TYPE(v)->tp_name); \
PyErr_Format(PyExc_TypeError, "expected a code-like, got %T", v); \
return NULL; \
}

View file

@ -5,8 +5,7 @@ static int
pytime_from_nanoseconds(PyTime_t *tp, PyObject *obj)
{
if (!PyLong_Check(obj)) {
PyErr_Format(PyExc_TypeError, "expect int, got %s",
Py_TYPE(obj)->tp_name);
PyErr_Format(PyExc_TypeError, "expect int, got %T", obj);
return -1;
}

View file

@ -515,8 +515,7 @@ test_thread_state(PyObject *self, PyObject *args)
return NULL;
if (!PyCallable_Check(fn)) {
PyErr_Format(PyExc_TypeError, "'%s' object is not callable",
Py_TYPE(fn)->tp_name);
PyErr_Format(PyExc_TypeError, "'%T' object is not callable", fn);
return NULL;
}

View file

@ -2207,8 +2207,7 @@ get_code(PyObject *obj)
return (PyCodeObject *)PyFunction_GetCode(obj);
}
return (PyCodeObject *)PyErr_Format(
PyExc_TypeError, "expected function or code object, got %s",
Py_TYPE(obj)->tp_name);
PyExc_TypeError, "expected function or code object, got %T", obj);
}
static PyObject *