mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
bpo-20092. Use __index__ in constructors of int, float and complex. (GH-13108)
This commit is contained in:
parent
1a4d9ffa1a
commit
bdbad71b9d
15 changed files with 181 additions and 23 deletions
|
@ -984,7 +984,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
|
|||
}
|
||||
|
||||
nbr = r->ob_type->tp_as_number;
|
||||
if (nbr == NULL || nbr->nb_float == NULL) {
|
||||
if (nbr == NULL || (nbr->nb_float == NULL && nbr->nb_index == NULL)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"complex() first argument must be a string or a number, "
|
||||
"not '%.200s'",
|
||||
|
@ -996,7 +996,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
|
|||
}
|
||||
if (i != NULL) {
|
||||
nbi = i->ob_type->tp_as_number;
|
||||
if (nbi == NULL || nbi->nb_float == NULL) {
|
||||
if (nbi == NULL || (nbi->nb_float == NULL && nbi->nb_index == NULL)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"complex() second argument must be a number, "
|
||||
"not '%.200s'",
|
||||
|
@ -1052,7 +1052,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
|
|||
/* The "imag" part really is entirely imaginary, and
|
||||
contributes nothing in the real direction.
|
||||
Just treat it as a double. */
|
||||
tmp = (*nbi->nb_float)(i);
|
||||
tmp = PyNumber_Float(i);
|
||||
if (tmp == NULL)
|
||||
return NULL;
|
||||
ci.real = PyFloat_AsDouble(tmp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue