mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
Issue #16290: __complex__ must now always return an instance of complex.
This commit is contained in:
parent
2eb2f5e359
commit
d20fb82195
3 changed files with 11 additions and 6 deletions
|
|
@ -271,6 +271,12 @@ try_complex_special_method(PyObject *op) {
|
|||
if (f) {
|
||||
PyObject *res = PyObject_CallFunctionObjArgs(f, NULL);
|
||||
Py_DECREF(f);
|
||||
if (res != NULL && !PyComplex_Check(res)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"__complex__ should return a complex object");
|
||||
Py_DECREF(res);
|
||||
return NULL;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return NULL;
|
||||
|
|
@ -296,12 +302,6 @@ PyComplex_AsCComplex(PyObject *op)
|
|||
newop = try_complex_special_method(op);
|
||||
|
||||
if (newop) {
|
||||
if (!PyComplex_Check(newop)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"__complex__ should return a complex object");
|
||||
Py_DECREF(newop);
|
||||
return cv;
|
||||
}
|
||||
cv = ((PyComplexObject *)newop)->cval;
|
||||
Py_DECREF(newop);
|
||||
return cv;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue