summaryrefslogtreecommitdiff
path: root/Objects/tupleobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r--Objects/tupleobject.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index c0383a1e09..384b355a10 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -584,11 +584,14 @@ static PySequenceMethods tuple_as_sequence = {
(objobjproc)tuplecontains, /* sq_contains */
};
+#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
+
static PyObject*
tuplesubscript(PyTupleObject* self, PyObject* item)
{
- if (PyInt_Check(item) || PyLong_Check(item)) {
- Py_ssize_t i = PyInt_AsSsize_t(item);
+ PyNumberMethods *nb = item->ob_type->tp_as_number;
+ if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
+ Py_ssize_t i = nb->nb_index(item);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)