gh-130821: Add type information to error messages for invalid return type (GH-130835)

This commit is contained in:
Semyon Moroz 2025-08-14 08:04:41 +00:00 committed by GitHub
parent c9d7065188
commit 968f6e523a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 76 additions and 76 deletions

View file

@ -566,8 +566,8 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen)
return NULL;
if (!PyBytes_Check(result)) {
PyErr_Format(PyExc_TypeError,
"__bytes__ returned non-bytes (type %.200s)",
Py_TYPE(result)->tp_name);
"%T.__bytes__() must return a bytes, not %T",
v, result);
Py_DECREF(result);
return NULL;
}
@ -2793,8 +2793,8 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
return NULL;
if (!PyBytes_Check(bytes)) {
PyErr_Format(PyExc_TypeError,
"__bytes__ returned non-bytes (type %.200s)",
Py_TYPE(bytes)->tp_name);
"%T.__bytes__() must return a bytes, not %T",
x, bytes);
Py_DECREF(bytes);
return NULL;
}