Prefer pythonnet's structured bind-failure data over message parsing - #9663
Closed
jhonabreul wants to merge 2 commits into
Closed
Prefer pythonnet's structured bind-failure data over message parsing#9663jhonabreul wants to merge 2 commits into
jhonabreul wants to merge 2 commits into
Conversation
NoMethodMatchPythonExceptionInterpreter now reads the method name and overloads hint from the attributes pythonnet attaches to the bind-failure TypeError (_clr_method_name, _clr_overloads_hint) instead of parsing them out of the exception message. When the attributes are absent (older pythonnet versions) or unreadable, it silently falls back to the existing message parsing. The rendered user-facing message is unchanged.
Closed
5 tasks
jhonabreul
marked this pull request as ready for review
August 11, 2026 17:50
jhonabreul
requested review from
Martin-Molinero
and
a lite review from Copilot
and removed request for
Martin-Molinero and
Copilot
August 11, 2026 17:50
jhonabreul
marked this pull request as draft
August 11, 2026 17:50
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.
Description
NoMethodMatchPythonExceptionInterpreternow prefers the structured data pythonnet attaches to the bind-failure TypeError —_clr_method_nameand_clr_overloads_hintattributes on the exception instance — over parsing them out of the exception message. When the attributes are absent (any pythonnet version released so far) or cannot be read, the interpreter silently falls back to the existing message parsing, which is left intact. The rendered user-facing message is unchanged in both paths.Pairs with QuantConnect/pythonnet#148, which attaches the attributes; this PR degrades gracefully without it, so it can be merged independently and does not require a pythonnet version bump.
Related Issue
Part of the error-surface improvements from the fleet-evidence study (QuantConnect/Agents#305, improvement 1): the interpreter's string parsing of pythonnet's message has garbled user-facing errors before (#9573, #9594); reading structured fields removes that coupling going forward.
Motivation and Context
Lean currently reconstructs the failed method name and the overloads hint by string-parsing pythonnet's TypeError message, a contract that has silently drifted before and produced garbled messages like
required by the 'int'>) method. With pythonnet attaching the underlying data as exception attributes, the interpreter reads fields instead of parsing prose, and only falls back to parsing for older pythonnet versions.Requires Documentation Change
None.
How Has This Been Tested?
NoMethodMatchPythonExceptionInterpreterTests: one verifying the structured attributes take precedence over the message contents when present, one verifying the fallback to message parsing when they are absent. Both use synthesized TypeErrors from theTest_PythonExceptionInterpreterfixture, so they run against the currently referenced pythonnet package.NoMethodMatchPythonExceptionInterpreterTests(real bind failures through the referenced pythonnet) still pass, covering the fallback path end-to-end.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>