Skip to content

Dead code in PyNumber_AsSsize_t() at L1542#112634

@skirpichev

Description

@skirpichev

cpython/Objects/abstract.c

Lines 1526 to 1542 in 18203a6

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions