Make `IntoPyObject` fallible for all integer conversions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
See: https://github.com/PyO3/pyo3/pull/6016#discussion_r3227568326, https://github.com/PyO3/pyo3/pull/6016#discussion_r3227310942
Currently IntoPyObject for all primitive integer types (u8..u128, i8..i128, usize, isize,
their NonZero<…> wrappers, and & references) uses type Error = Infallible. This means the
underlying FFI calls — PyLong_FromLong, PyLong_FromLongLong, PyLong_FromNativeBytes,
PyLongWriter_Create / PyLongWriter_Finish — panic on failure (NULL return) via
assume_owned, rather than propagating a PyErr.
These failures are very rare in practice (allocation failure, interpreter shutdown, MemoryError),
but they can happen, and panicking across an FFI boundary is the worst possible reaction.
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 by tracing the IntoPyObject implementations for primitive integers, NonZero wrappers, and references through assume_owned and the listed PyLong FFI calls. Check how failures are represented elsewhere, then verify that every listed conversion propagates a PyErr instead of panicking on a NULL return.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100