-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Better error messages when calling overloaded function with invalid types. #5054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hm, I don't think this is all that helpful. It should at least indicate which variants could match the arguments and which couldn't -- e.g. when there is one argument, don't show overloads with zero or two arguments. The examples in the tests make me think that the messages produced with this PR are too verbose (as opposed to being too terse, as before :-). |
@MentalMegalodon -- would you be interested in continuing work on this? It'll unfortunately be a bit of a slog due to the merge conflicts (we've been making a variety of improvements to overloads over the past month). The plus side is that addressing @gvanrossum's feedback should be easier now due to these changes: I think it basically boils down passing in the If you're not interested in continuing work on this, let me know and I can take over. |
Resolves python#672 and supercedes python#5054. Currently, if a user calls an overloaded function and mypy is unable to find a match, mypy will display display a warning like 'No overload variant of "func" matches argument types" with no additional context. This pull request will list several matching variants in addition to that message. If possible, mypy will attempt to show only overloads that have a compatible number of arguments. The number of overloads shown is always capped at a maximum of 2. This pull request does *not* attempt to report a custom error when... 1. Union-math fails. Rationale: the pending PR will change how unions are handled dramatically enough to the point where any error handling here would be pointless. 2. Mypy is able to infer what signature the user most likely meant by looking at the erased types. Rationale: I attempted to implement this feature but was unable to make it consistently work without adding several ugly hacks around how mypy records errors so decided to defer implementing this feature.
OK, this is now superseded by #5296 Thanks for your work @MentalMegalodon! |
List possible overload variants when none match Resolves #672 and supersedes #5054. Currently, if a user calls an overloaded function and mypy is unable to find a match, mypy will display display a warning like 'No overload variant of "func" matches argument types" with no additional context. This pull request will list several matching variants in addition to that message. If possible, mypy will attempt to show only overloads that have a compatible number of arguments. The total number of extra lines of output printed is capped at 4 -- this means that the number of overloads shown is typically capped to a max of either 2 or 3. This pull request does *not* attempt to report a custom error when... 1. Union-math fails. Rationale: the pending PR will change how unions are handled dramatically enough to the point where any error handling here would be pointless. 2. Mypy is able to infer what signature the user most likely meant by looking at the erased types. Rationale: I attempted to implement this feature but was unable to make it consistently work without adding several ugly hacks around how mypy records errors so decided to defer implementing this feature.
Fixes #672