summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-06-01 21:05:48 (GMT)
committerGitHub <noreply@github.com>2019-06-01 21:05:48 (GMT)
commitbdbad71b9def0b86433de12cecca022eee91bd9f (patch)
tree147c8a3e08454a95e0e4900388d88f7b65430f63 /Objects/floatobject.c
parent1a4d9ffa1aecd7e750195f2be06d3d16c7a3a88f (diff)
downloadcpython-bdbad71b9def0b86433de12cecca022eee91bd9f.zip
cpython-bdbad71b9def0b86433de12cecca022eee91bd9f.tar.gz
cpython-bdbad71b9def0b86433de12cecca022eee91bd9f.tar.bz2
bpo-20092. Use __index__ in constructors of int, float and complex. (GH-13108)
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 2bf7061..15cbe5c 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -246,6 +246,15 @@ PyFloat_AsDouble(PyObject *op)
nb = Py_TYPE(op)->tp_as_number;
if (nb == NULL || nb->nb_float == NULL) {
+ if (nb && nb->nb_index) {
+ PyObject *res = PyNumber_Index(op);
+ if (!res) {
+ return -1;
+ }
+ double val = PyLong_AsDouble(res);
+ Py_DECREF(res);
+ return val;
+ }
PyErr_Format(PyExc_TypeError, "must be real number, not %.50s",
op->ob_type->tp_name);
return -1;