Skip to content

Commit 2706a66

Browse files
committed
address code review
1 parent eaf7662 commit 2706a66

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

Python/ceval.c

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,38 +2884,10 @@ PyEval_GetFuncDesc(PyObject *func)
28842884
int
28852885
_PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
28862886
{
2887-
PyThreadState *tstate = _PyThreadState_GET();
2888-
if (!Py_IsNone(v)) {
2889-
Py_ssize_t x;
2890-
if (PyLong_CheckExact(v)) {
2891-
// Fast path for compact ints (single digit) -- most slice indices.
2892-
if (_PyLong_IsCompact((PyLongObject *)v)) {
2893-
x = _PyLong_CompactValue((PyLongObject *)v);
2894-
}
2895-
else {
2896-
x = PyLong_AsSsize_t(v);
2897-
if (x == -1 && _PyErr_Occurred(tstate)) {
2898-
assert(_PyErr_ExceptionMatches(tstate, PyExc_OverflowError));
2899-
_PyErr_Clear(tstate);
2900-
x = _PyLong_IsNegative((PyLongObject *)v)
2901-
? PY_SSIZE_T_MIN : PY_SSIZE_T_MAX;
2902-
}
2903-
}
2904-
}
2905-
else if (_PyIndex_Check(v)) {
2906-
x = PyNumber_AsSsize_t(v, NULL);
2907-
if (x == -1 && _PyErr_Occurred(tstate))
2908-
return 0;
2909-
}
2910-
else {
2911-
_PyErr_SetString(tstate, PyExc_TypeError,
2912-
"slice indices must be integers or "
2913-
"None or have an __index__ method");
2914-
return 0;
2915-
}
2916-
*pi = x;
2887+
if (Py_IsNone(v)) {
2888+
return 1;
29172889
}
2918-
return 1;
2890+
return _PyEval_SliceIndexNotNone(v, pi);
29192891
}
29202892

29212893
int

0 commit comments

Comments
 (0)