Skip to content

Commit 5d062d7

Browse files
Issue python#27333: Simplified testing step on 0.
1 parent cfdfbb4 commit 5d062d7

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

‎Objects/rangeobject.c‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,10 @@ validate_step(PyObject *step)
2929
return PyLong_FromLong(1);
3030

3131
step = PyNumber_Index(step);
32-
if (step) {
33-
Py_ssize_t istep = PyNumber_AsSsize_t(step, NULL);
34-
if (istep == -1 && PyErr_Occurred()) {
35-
/* Ignore OverflowError, we know the value isn't 0. */
36-
PyErr_Clear();
37-
}
38-
else if (istep == 0) {
39-
PyErr_SetString(PyExc_ValueError,
40-
"range() arg 3 must not be zero");
41-
Py_CLEAR(step);
42-
}
32+
if (step && _PyLong_Sign(step) == 0) {
33+
PyErr_SetString(PyExc_ValueError,
34+
"range() arg 3 must not be zero");
35+
Py_CLEAR(step);
4336
}
4437

4538
return step;

0 commit comments

Comments
 (0)