Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b9c667

Browse files
committed
Better error message if stride used on normal sequence object
1 parent 6ffd553 commit 3b9c667

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

Python/ceval.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,6 +2529,9 @@ call_function(func, arg, kw)
25292529
return result;
25302530
}
25312531

2532+
#define SLICE_ERROR_MSG \
2533+
"standard sequence type does not support step size other than one"
2534+
25322535
static object *
25332536
apply_subscript(v, w)
25342537
object *v, *w;
@@ -2543,8 +2546,13 @@ apply_subscript(v, w)
25432546
}
25442547
else {
25452548
int i;
2546-
if (!is_intobject(w)) {
2547-
err_setstr(TypeError, "sequence subscript not int");
2549+
if (!is_intobject(w)) {
2550+
if (PySlice_Check(w)) {
2551+
err_setstr(ValueError, SLICE_ERROR_MSG);
2552+
} else {
2553+
err_setstr(TypeError,
2554+
"sequence subscript not int");
2555+
}
25482556
return NULL;
25492557
}
25502558
i = getintvalue(w);

0 commit comments

Comments
 (0)