mirror of
https://github.com/python/cpython.git
synced 2025-12-11 19:40:17 +00:00
gh-130821: Add type information to error messages for invalid return type (GH-130835)
This commit is contained in:
parent
c9d7065188
commit
968f6e523a
14 changed files with 76 additions and 76 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue