You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Give better error messages when calling overloaded function with invalid types #672
Currently when calling an overloaded function, the error message is something like No overload variant of "foo" matches argument types. Instead, we should try to give a message like Argument 1 to "foo" has incompatible type "int"; expected "str" or "bytes", which is more informative. This may not be always possible, but we should be able to do it at least most of the time.
Also, if we can't give a specific message, we could print out the full signature of the target overloaded function as a note after the message. This would make it easier to see why the call is rejected by mypy.
I think just listing argument types and the overloads in a note may be enough. Also protocol notes already contain relevant code for nice compact formatting of overloads.
The implementation of protocol notes lives in report_protocol_problems in mypy.messages. Overload messages are generated in no_variant_matches_arguments in the same module.
Activity
JukkaL commentedon May 23, 2017
Also, if we can't give a specific message, we could print out the full signature of the target overloaded function as a note after the message. This would make it easier to see why the call is rejected by mypy.
ilevkivskyi commentedon May 14, 2018
I think just listing argument types and the overloads in a note may be enough. Also protocol notes already contain relevant code for nice compact formatting of overloads.
JukkaL commentedon May 14, 2018
The implementation of protocol notes lives in
report_protocol_problemsinmypy.messages. Overload messages are generated inno_variant_matches_argumentsin the same module.MentalMegalodon commentedon May 15, 2018
I'm working on it.
List possible overload variants when none match
List possible overload variants when none match (#5296)