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

@ -288,16 +288,16 @@ PyFloat_AsDouble(PyObject *op)
if (!PyFloat_CheckExact(res)) {
if (!PyFloat_Check(res)) {
PyErr_Format(PyExc_TypeError,
"%.50s.__float__ returned non-float (type %.50s)",
Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name);
"%T.__float__() must return a float, not %T",
op, res);
Py_DECREF(res);
return -1;
}
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"%.50s.__float__ returned non-float (type %.50s). "
"%T.__float__() must return a float, not %T. "
"The ability to return an instance of a strict subclass of float "
"is deprecated, and may be removed in a future version of Python.",
Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name)) {
op, res)) {
Py_DECREF(res);
return -1;
}