summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-30 20:32:18 +0300
committerGitHub <noreply@github.com>2017-03-30 20:32:18 +0300
commit079f21f873b99f9564a41c5b7f3e0d7035847ae5 (patch)
tree5ac4ae180b310f303b1545dd9b6b77ac486af133 /Python
parent3ceca68741f8a2d3a4436b6d54eae76aa5bcc4c5 (diff)
downloadcpython-git-079f21f873b99f9564a41c5b7f3e0d7035847ae5.tar.gz
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)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c22
1 files changed, 21 insertions, 1 deletions
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))