Repository navigation
Conversation
int_::operator T() ignored errors from PyLong_As* and truncated values that did not fit in types narrower than long. It now throws error_already_set on failure and raises OverflowError when the value is out of range for T. Fixes pybind#2786. Assisted-by: ClaudeCode:claude-opus-5-5
|
— codex on behalf of Ralf — Clarify or implement the advertised Ralf has yet to review these findings. |
The bool conversion read the value as unsigned long first, so negative and very large integers raised OverflowError. Assisted-by: ClaudeCode:claude-fable-5-2
|
🤖 AI text below 🤖 Confirmed. Fixed in 167ce1d: the One related item, not changed here: |
🤖 AI text below 🤖
Description
Fixes #2786. Supersedes the stale draft, close #2802.
int_::operator T()did not check for errors fromPyLong_AsLongand related calls. On overflow it returned-1with the Python error still set, which later gave aSystemError. For types narrower thanlong(for exampleinton LP64), out-of-range values were silently truncated.The conversion now throws
error_already_setwhen the read fails, and raisesOverflowErrorwhen the value does not fit inT. Implicit conversion tobooluses truthiness (PyObject_IsTrue), so it has no range limit.Suggested changelog entry:
py::int_conversion to C++ integer types now raisesOverflowErrorfor out-of-range values instead of truncating or leaving a Python error set.📚 Documentation preview 📚: https://pybind11--6257.org.readthedocs.build/