Skip to content

[C API] Add PyLong_AsInt() public function #108444

Closed
@vstinner

Description

@vstinner

Feature or enhancement

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Proposal:

The _PyLong_AsInt() function was added in 2013 by commit 74f49ab. It was added a private function (_Py) prefix and it's not part of the limited C API.

This function is widely used in the Python code base which means that it's useful. Casting PyLong_AsLong() to int and then checking for overflow is error prone, it requires to raise the right exception.

Using a private function is a bad practive: I removed many private functions from Python 3.13 C API, see issue #106320.

I propose to add PyLong_AsInt() to the limited C API, add documentation and tests.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions