summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-02-25 15:57:58 (GMT)
committerGitHub <noreply@github.com>2019-02-25 15:57:58 (GMT)
commit6a44f6eef3d0958d88882347190b3e2d1222c2e9 (patch)
treebb6474b1e094a672837c3333a081fa4d5d7638f2 /Objects/abstract.c
parentd90a141bb947b68601f8d1f37bc98f7b524f0e01 (diff)
downloadcpython-6a44f6eef3d0958d88882347190b3e2d1222c2e9.zip
cpython-6a44f6eef3d0958d88882347190b3e2d1222c2e9.tar.gz
cpython-6a44f6eef3d0958d88882347190b3e2d1222c2e9.tar.bz2
bpo-36048: Use __index__() instead of __int__() for implicit conversion if available. (GH-11952)
Deprecate using the __int__() method in implicit conversions of Python numbers to C integers.
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 0565ba3..68d06ed 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -759,8 +759,9 @@ int
PyNumber_Check(PyObject *o)
{
return o && o->ob_type->tp_as_number &&
- (o->ob_type->tp_as_number->nb_int ||
- o->ob_type->tp_as_number->nb_float);
+ (o->ob_type->tp_as_number->nb_index ||
+ o->ob_type->tp_as_number->nb_int ||
+ o->ob_type->tp_as_number->nb_float);
}
/* Binary operators */
@@ -1366,7 +1367,7 @@ PyNumber_Long(PyObject *o)
}
m = o->ob_type->tp_as_number;
if (m && m->nb_int) { /* This should include subclasses of int */
- result = (PyObject *)_PyLong_FromNbInt(o);
+ result = _PyLong_FromNbInt(o);
if (result != NULL && !PyLong_CheckExact(result)) {
Py_SETREF(result, _PyLong_Copy((PyLongObject *)result));
}
@@ -1386,7 +1387,7 @@ PyNumber_Long(PyObject *o)
/* __trunc__ is specified to return an Integral type,
but int() needs to return an int. */
m = result->ob_type->tp_as_number;
- if (m == NULL || m->nb_int == NULL) {
+ if (m == NULL || (m->nb_index == NULL && m->nb_int == NULL)) {
PyErr_Format(
PyExc_TypeError,
"__trunc__ returned non-Integral (type %.200s)",
@@ -1394,7 +1395,7 @@ PyNumber_Long(PyObject *o)
Py_DECREF(result);
return NULL;
}
- Py_SETREF(result, (PyObject *)_PyLong_FromNbInt(result));
+ Py_SETREF(result, _PyLong_FromNbIndexOrNbInt(result));
if (result != NULL && !PyLong_CheckExact(result)) {
Py_SETREF(result, _PyLong_Copy((PyLongObject *)result));
}