Attach structured bind-failure data to the no-method-matches TypeError - #148
Closed
jhonabreul wants to merge 2 commits into
Closed
Attach structured bind-failure data to the no-method-matches TypeError#148jhonabreul wants to merge 2 commits into
jhonabreul wants to merge 2 commits into
Conversation
When no overload matches a call, the TypeError now carries the data its message is built from as attributes on the exception instance: _clr_method_name (snake_case method name), _clr_overload_signatures (tuple of formatted signatures) and _clr_overloads_hint (the rendered hint block appended to the message). Consumers such as Lean's exception interpreters can read these instead of parsing the message. The message itself is unchanged, and attribute attachment is best-effort: on any failure the plain TypeError with the same message is raised.
11 tasks
Collaborator
Author
|
Paired Lean PR that consumes the structured attributes (with graceful fallback to message parsing): QuantConnect/Lean#9663 |
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.
What does this implement/fix? Explain your changes.
When a method call cannot be bound to any overload, the raised TypeError now carries the data its message is built from as attributes on the exception instance, so consumers can read them directly instead of parsing the message:
_clr_method_name(str): the snake_case method name shown in the message_clr_overload_signatures(tuple of str): the formatted candidate signatures_clr_overloads_hint(str): the rendered hint block ("The expected signature is:" / "The following overloads are available:" plus signatures) exactly as it appears at the end of the messageEach attribute is only present when the corresponding information is available. The human-readable message is byte-for-byte unchanged, so existing consumers that parse it (e.g. current Lean releases) keep working. Attribute attachment is best-effort: on any failure the plain TypeError with the same message is raised.
MethodSignatureFormatter.FormatOverloadsis split intoGetSignatures+FormatOverloadsHintso the binder can attach the same signature list the message shows; its output is unchanged.Pairs with a Lean PR that makes
NoMethodMatchPythonExceptionInterpreterprefer these attributes and fall back to message parsing (linked in comments below).Does this close any currently open issues?
No open issue in this repo; part of the error-surface improvements from the fleet-evidence study (QuantConnect/Agents#305, improvement 1).
Any other comments?
The attribute names are defined as internal constants in
Exceptions(BindFailure*Attribute). They are intentionally not public static fields:Exceptions.Initialize()resolves every public static field of that class against thebuiltinsmodule at engine startup.Checklist
Check all those that are applicable and complete.
AUTHORSCHANGELOG