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
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 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.boolkeeps truthiness semantics (no range check).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.