See: #6016 (comment), #6016 (comment)
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.
See: #6016 (comment), #6016 (comment)
Currently
IntoPyObjectfor all primitive integer types (u8..u128,i8..i128,usize,isize,their
NonZero<…>wrappers, and&references) usestype Error = Infallible. This means theunderlying FFI calls —
PyLong_FromLong,PyLong_FromLongLong,PyLong_FromNativeBytes,PyLongWriter_Create/PyLongWriter_Finish— panic on failure (NULL return) viaassume_owned, rather than propagating aPyErr.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.