Repository navigation
fix: do not discard unrelated errors in the arithmetic caster - #6297
Merged
Merged
Conversation
The arithmetic type caster cleared every error raised during conversion. A KeyboardInterrupt or RuntimeError from __index__, __int__, or __float__ was lost: the call used the __int__ result or failed with "incompatible function arguments". Clear only TypeError, ValueError, and OverflowError, which mean "does not convert", and propagate other errors. Assisted-by: ClaudeCode:claude-fable-5-2
henryiii
marked this pull request as ready for review
November 23, 2026 22:34
Collaborator
|
— codex on behalf of Ralf — No actionable findings. The three error-clearing sites now preserve unrelated Python exceptions, while |
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
Part of #2862. This changes only the arithmetic caster.
The arithmetic
type_caster::loadcalledPyErr_Clear()in three places without checking the error. AKeyboardInterruptorRuntimeErrorfrom__index__,__int__, or__float__was lost: the call used the__int__result or failed with "incompatible function arguments". A new helper clears onlyTypeError,ValueError, andOverflowError(the "does not convert" errors) and throwserror_already_setfor other errors.Behavior changes:
py::cast<int>(obj)raiseserror_already_setinstead ofcast_errorin that case.ValueErroris still cleared because an existing test expects aValueErrorfrom__index__to fall back to__int__.PyNumber_Longalso raisesValueErrorfor NaN.Primary-error policy: this change removes paths that discard the primary error and adds none.
Suggested changelog entry:
TypeError,ValueError, andOverflowError(for exampleKeyboardInterrupt) raised during conversion.