|
PyObject *value = _PyNumber_Index(item); |
|
if (value == NULL) |
|
return -1; |
|
|
|
/* We're done if PyLong_AsSsize_t() returns without error. */ |
|
result = PyLong_AsSsize_t(value); |
|
if (result != -1) |
|
goto finish; |
|
|
|
PyThreadState *tstate = _PyThreadState_GET(); |
|
runerr = _PyErr_Occurred(tstate); |
|
if (!runerr) { |
|
goto finish; |
|
} |
|
|
|
/* Error handling code -- only manage OverflowError differently */ |
|
if (!PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) { |
But according to the docs (https://docs.python.org/3/c-api/long.html?#c.PyLong_AsSsize_t), PyLong_AsSsize_t() call above may raise only OverflowError (at that line "value" - is an int or int subclass). I think we can turn this line to an assert (or just remove it entirely).
// transformed to a separate issue per @serhiy-storchaka suggestion in #112145
Linked PRs
cpython/Objects/abstract.c
Lines 1526 to 1542 in 18203a6
But according to the docs (https://docs.python.org/3/c-api/long.html?#c.PyLong_AsSsize_t), PyLong_AsSsize_t() call above may raise only OverflowError (at that line "value" - is an int or int subclass). I think we can turn this line to an assert (or just remove it entirely).
// transformed to a separate issue per @serhiy-storchaka suggestion in #112145
Linked PRs