| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
When a method call fails to bind and one of the supplied keyword arguments
matches no parameter of any candidate overload, the generic 'No method
matches given arguments' message did not mention the keyword argument at
all (only positional argument types are echoed), leaving the actual
mistake invisible, e.g.:
market_order(symbol, -10, as_tag="EmergencyFlatten")
-> No method matches given arguments for market_order:
(<class 'Symbol'>, <class 'int'>). The following overloads ...
Now such calls raise the Python-style error instead, naming the offending
kwarg and suggesting the closest parameter name when one exists:
market_order() got an unexpected keyword argument 'as_tag'.
Did you mean 'tag'?
When every kwarg name is valid for some overload but binding still fails,
the existing no-method-matches message is preserved.
Moves ClassBase's private LevenshteinDistance implementation verbatim to Util.LevenshteinDistance and uses it from both call sites, removing the duplicate introduced for keyword-argument suggestions.
…d of replacing it
Keeps the Jaro-Winkler scoring from this branch in ClassBase while retaining Util.LevenshteinDistance, which MethodBinder's unexpected-kwarg suggestion (QuantConnect#144) still uses. Also moves the DiagnoseClosestOverloadMismatch block inside the bind-failure try so master compiles again: QuantConnect#144 wrapped the message construction (including the candidates declaration) in try/catch after QuantConnect#145 had added the mismatch diagnosis below it, leaving 'candidates' out of scope at its use site.
| Back | FazBrowse Home | New Git URL |
What does this implement/fix? Explain your changes.
When a call fails to bind because of a misspelled keyword argument, the error did not mention the kwarg at all — only positional argument types are echoed — so the actual mistake was invisible:
Cause: MethodBinder.Invoke's bind-failure path builds its message from the positional args tuple only and has no unexpected-keyword-argument path.
The fix:
MethodBinder.AppendUnexpectedKeywordArgument runs while the bind-failure message is built: when a supplied kwarg name is accepted by no candidate overload (same candidate set Bind used, so snake_case and original parameter names are matched exactly like binding does), it extends the existing message — right after the positional argument types, before the overload list — naming the first unknown kwarg in call order like CPython:
The Did you mean hint suggests the closest parameter name across all overloads (small local Levenshtein plus containment for 3+ character names); it is omitted when nothing is similar.
When every kwarg name is valid for some overload but binding still fails (e.g. a type mismatch, or an argument supplied both positionally and by name), the message is unchanged.
The whole message-construction block (including the pre-existing name/argument-types/overloads parts) is now wrapped in a try/catch: it runs over arbitrary caller input inside the tp_call slot, where an escaping exception would propagate into CPython and mask the bind failure; on error the TypeError is raised with whatever was appended so far.
A complete message as produced against the new test fixture:
Note: the message keeps the No method matches given arguments for {name}: prefix, so Lean's NoMethodMatchPythonExceptionInterpreter keeps matching and rewriting it exactly as before; the kwarg detail rides along inside it.
Note on #147: ClassBase's private LevenshteinDistance moved verbatim to Util.LevenshteinDistance, used by both ClassBase and MethodBinder. #147 deletes the ClassBase call site in favor of Jaro-Winkler; the shared helper remains for MethodBinder, so the merge interplay is a trivial deletion on their side.
Does this close any currently open issues?
No. Part of the error-surface improvements from QuantConnect/Agents#305 (improvement 1: fleet evidence A-70ad2e3b).
Any other comments?
Tests:
Checklist
Check all those that are applicable and complete.