Pinpoint the first mismatched argument in bind-failure TypeErrors - #145
Merged
jhonabreul merged 2 commits intoAug 12, 2026
Merged
Conversation
When no overload matches a call, the TypeError now appends a diagnosis of
the first argument that fails to match the nearest overload (the one with
the most leading convertible arguments), e.g.:
Argument mismatch: argument 3 ('asynchronous') expected bool, got str.
Keyword arguments whose values cannot convert to the matching parameter
are diagnosed too. The line is appended after the overloads hint so
consumers that extract the hint from its marker onwards keep it.
Drops the duplicated type-name helper in favor of the existing runtime one, and tightens the new comments.
jhonabreul
marked this pull request as ready for review
August 11, 2026 18:06
Martin-Molinero
approved these changes
Aug 11, 2026
jhonabreul
added a commit
to jhonabreul/pythonnet
that referenced
this pull request
Aug 12, 2026
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.
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 call cannot be matched to any overload, the bind-failure
TypeErrornow pinpoints the first argument that fails to match the nearest overload (the candidate with the most leading convertible arguments), so the caller doesn't have to diff the hinted signatures by eye.Before:
After (last line is new):
Keyword arguments whose values cannot convert to the parameter they name are diagnosed too (
Argument mismatch: keyword argument 'tag' expected str, got int.).Details:
objectparameters,paramstails), so it under-reports rather than blames the wrong argument.NoMethodMatchPythonExceptionInterpreter, which keeps the message from theThe following overloads are available:marker onwards, surfaces it to users unchanged. TheNo method matches given arguments for {name}: (...)prefix is untouched.TypeErroris raised.Does this close any currently open issues?
Part of the pythonnet overload/attribute error-surface improvements (QuantConnect/Agents#305, improvement 1: show the nearest overload with the first mismatching parameter highlighted).
Any other comments?
The fleet's most common failure shape motivating this is a positional string tag landing in the
asynchronous: boolslot of the order methods, e.g.self.market_order(symbol, -quantity, "exit signal").Checklist
Check all those that are applicable and complete.
AUTHORSCHANGELOG