diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-05-26 15:43:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-26 15:43:38 (GMT) |
commit | 578c3955e0222ec7b3146197467fbb0fcfae12fe (patch) | |
tree | 1314ca1eb6153feaf3fb1cae341784270ce24c32 /Modules/arraymodule.c | |
parent | 8ad052464a4e0aef9a11663b80f187087b773592 (diff) | |
download | cpython-578c3955e0222ec7b3146197467fbb0fcfae12fe.zip cpython-578c3955e0222ec7b3146197467fbb0fcfae12fe.tar.gz cpython-578c3955e0222ec7b3146197467fbb0fcfae12fe.tar.bz2 |
bpo-37999: No longer use __int__ in implicit integer conversions. (GH-15636)
Only __index__ should be used to make integer conversions lossless.
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r-- | Modules/arraymodule.c | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 732703e..fb1b82c 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -337,17 +337,6 @@ II_getitem(arrayobject *ap, Py_ssize_t i) (unsigned long) ((unsigned int *)ap->ob_item)[i]); } -static PyObject * -get_int_unless_float(PyObject *v) -{ - if (PyFloat_Check(v)) { - PyErr_SetString(PyExc_TypeError, - "array item must be integer"); - return NULL; - } - return _PyLong_FromNbIndexOrNbInt(v); -} - static int II_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) { @@ -355,7 +344,7 @@ II_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) int do_decref = 0; /* if nb_int was called */ if (!PyLong_Check(v)) { - v = get_int_unless_float(v); + v = PyNumber_Index(v); if (NULL == v) { return -1; } @@ -415,7 +404,7 @@ LL_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) int do_decref = 0; /* if nb_int was called */ if (!PyLong_Check(v)) { - v = get_int_unless_float(v); + v = PyNumber_Index(v); if (NULL == v) { return -1; } @@ -468,7 +457,7 @@ QQ_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) int do_decref = 0; /* if nb_int was called */ if (!PyLong_Check(v)) { - v = get_int_unless_float(v); + v = PyNumber_Index(v); if (NULL == v) { return -1; } |