Provide custom error messages for overflows in PyLong_AsLong/PyLong_AsInt()
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
Proposal:
Both functions have old TODO comments:
https://github.com/python/cpython/blob/453d886f8592d2f4346d5621b1e4ff31c24338d5/Objects/longobject.c#L671-L676
https://github.com/python/cpython/blob/453d886f8592d2f4346d5621b1e4ff31c24338d5/Objects/longobject.c#L688-L694
Lets either remove these marks or provide different error messages, for example for longs:
if (overflow > 0) {
PyErr_Format(PyExc_OverflowError,
"Python int too large to convert to C long, value > %ld",
LONG_MAX);
return -1;
}
else if (overflow < 0) {
PyErr_Format(PyExc_OverflowError,
"Python int too large to convert to C long, value < %ld",
LONG_MIN);
return -1;
}
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
- gh-141585
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Objects/longobject.c at the TODO comments linked in the issue, and review linked PR gh-141585 for the work already underway. Done means either removing those TODOs or providing distinct overflow messages for PyLong_AsLong() and PyLong_AsInt().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100