Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8dabbf1

Browse files
committed
Fix for the bug in complex() just reported by Ping.
1 parent 90cb906 commit 8dabbf1

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Python/bltinmodule.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,12 +591,18 @@ builtin_complex(PyObject *self, PyObject *args)
591591
}
592592
}
593593
else {
594-
tmp = (*nbr->nb_float)(r);
594+
tmp = PyNumber_Float(r);
595595
if (own_r) {
596596
Py_DECREF(r);
597597
}
598598
if (tmp == NULL)
599599
return NULL;
600+
if (!PyFloat_Check(tmp)) {
601+
PyErr_SetString(PyExc_TypeError,
602+
"float(r) didn't return a float");
603+
Py_DECREF(tmp);
604+
return NULL;
605+
}
600606
cr.real = PyFloat_AsDouble(tmp);
601607
Py_DECREF(tmp);
602608
cr.imag = 0.0;

0 commit comments

Comments
 (0)