mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-37999: No longer use __int__ in implicit integer conversions. (GH-15636)
Only __index__ should be used to make integer conversions lossless.
This commit is contained in:
parent
8ad052464a
commit
578c3955e0
87 changed files with 226 additions and 2937 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue