diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2019-06-02 00:05:48 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-02 00:05:48 +0300 |
| commit | bdbad71b9def0b86433de12cecca022eee91bd9f (patch) | |
| tree | 147c8a3e08454a95e0e4900388d88f7b65430f63 /Objects/complexobject.c | |
| parent | 1a4d9ffa1aecd7e750195f2be06d3d16c7a3a88f (diff) | |
| download | cpython-git-bdbad71b9def0b86433de12cecca022eee91bd9f.tar.gz | |
bpo-20092. Use __index__ in constructors of int, float and complex. (GH-13108)
Diffstat (limited to 'Objects/complexobject.c')
| -rw-r--r-- | Objects/complexobject.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c index a5f95186d6..f78c0fdf78 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -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); |
