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

@ -515,17 +515,17 @@ try_complex_special_method(PyObject *op)
}
if (!PyComplex_Check(res)) {
PyErr_Format(PyExc_TypeError,
"__complex__ returned non-complex (type %.200s)",
Py_TYPE(res)->tp_name);
"%T.__complex__() must return a complex, not %T",
op, res);
Py_DECREF(res);
return NULL;
}
/* Issue #29894: warn if 'res' not of exact type complex. */
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"__complex__ returned non-complex (type %.200s). "
"%T.__complex__() must return a complex, not %T. "
"The ability to return an instance of a strict subclass of complex "
"is deprecated, and may be removed in a future version of Python.",
Py_TYPE(res)->tp_name)) {
op, res)) {
Py_DECREF(res);
return NULL;
}