Skip to content

Attach structured bind-failure data to the no-method-matches TypeError - #148

Closed
jhonabreul wants to merge 2 commits into
QuantConnect:masterfrom
jhonabreul:feature-structured-bind-failure-info
Closed

Attach structured bind-failure data to the no-method-matches TypeError#148
jhonabreul wants to merge 2 commits into
QuantConnect:masterfrom
jhonabreul:feature-structured-bind-failure-info

Conversation

@jhonabreul

Copy link
Copy Markdown
Collaborator

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 message

Each 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.FormatOverloads is split into GetSignatures + FormatOverloadsHint so the binder can attach the same signature list the message shows; its output is unchanged.

Pairs with a Lean PR that makes NoMethodMatchPythonExceptionInterpreter prefer 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 the builtins module at engine startup.

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Ensure you have signed the .NET Foundation CLA
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

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.
@jhonabreul

Copy link
Copy Markdown
Collaborator Author

Paired Lean PR that consumes the structured attributes (with graceful fallback to message parsing): QuantConnect/Lean#9663

@jhonabreul jhonabreul closed this Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant