From 079f21f873b99f9564a41c5b7f3e0d7035847ae5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 30 Mar 2017 20:32:18 +0300 Subject: bpo-29935: Fixed error messages in the index() method of tuple and list (#887) (#907) (#910) when pass indices of wrong type. (cherry picked from commit d4edfc9abffca965e76ebc5957a92031a4d6c4d4) (cherry picked from commit bf4bb2e43030661e568d5d4b046e8b9351cc164c) --- Python/ceval.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'Python') diff --git a/Python/ceval.c b/Python/ceval.c index 0983651998..cea503e56f 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4689,7 +4689,7 @@ ext_call_fail: int _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi) { - if (v != NULL) { + if (v != NULL && v != Py_None) { Py_ssize_t x; if (PyInt_Check(v)) { /* XXX(nnorwitz): I think PyInt_AS_LONG is correct, @@ -4714,6 +4714,26 @@ _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi) return 1; } +int +_PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *pi) +{ + Py_ssize_t x; + if (PyIndex_Check(v)) { + x = PyNumber_AsSsize_t(v, NULL); + if (x == -1 && PyErr_Occurred()) + return 0; + } + else { + PyErr_SetString(PyExc_TypeError, + "slice indices must be integers or " + "have an __index__ method"); + return 0; + } + *pi = x; + return 1; +} + + #undef ISINDEX #define ISINDEX(x) ((x) == NULL || \ PyInt_Check(x) || PyLong_Check(x) || PyIndex_Check(x)) -- cgit v1.2.1