Skip to content

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

Closed
wants to merge 2 commits into from
Closed

Better error messages when calling overloaded function with invalid types. #5054

wants to merge 2 commits into from

Conversation

MentalMegalodon
Copy link
Contributor

Fixes #672

@gvanrossum
Copy link
Member

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 :-).

@Michael0x2a Michael0x2a mentioned this pull request May 29, 2018
20 tasks
@ilevkivskyi ilevkivskyi self-requested a review June 10, 2018 00:06
@ilevkivskyi ilevkivskyi self-assigned this Jun 10, 2018
@Michael0x2a
Copy link
Collaborator

@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 plausible_targets variable into the no_variant_matches_arguments function here and using that info to display a more useful list of variants. In the case that the list is empty, we could fall back to the current behavior or something.

If you're not interested in continuing work on this, let me know and I can take over.

Michael0x2a added a commit to Michael0x2a/mypy that referenced this pull request Jun 29, 2018
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.
@ilevkivskyi
Copy link
Member

OK, this is now superseded by #5296

Thanks for your work @MentalMegalodon!

Michael0x2a added a commit that referenced this pull request Jul 6, 2018
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.
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.

4 participants