PyO3 / PyO3/pyo3

Make `IntoPyObject` fallible for all integer conversions

Open
#6,039 0 comments 0 reactions 0 assignees View on GitHub

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_Finishpanic 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.