-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Confusing message if callable is incompatible due to argument name #4530
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
Comments
Added high priority since this is very confusing and we just received another report about this. |
Another similar example with even more confusing error message was found by @msullivan: from typing import Optional, List, Tuple, Dict, Callable
def foo(x: int) -> None: pass
def bar(x: int) -> None: pass
funcs = [foo, bar]
reveal_type(funcs)
def oops(x: List[Callable[[int], None]]) -> None:
reveal_type(x)
oops(funcs) produces the error message |
We should probably schedule this one for next sprint usability bugs squashing week. This happened again, it can very challenging with more complex signatures. |
We also run into similar issues with sufficiently complex overload signatures -- for example, I ended up being confused by this sort of thing in #5235. FWIW, one solution I was sort of tossing around was to modify or refactor |
Note that the error can be even more cryptic if type inference fails because of name mismatch, see #6928 for example. |
…rn types in error messages (#18495) Fixes #18493. Improves message in #12013 and #4530, but probably still doesn't make it clear enough. Use higher verbosity for type formatting in error message if callables' return types are compatible and supertype has some named arguments, as that is a popular source of confusion.
The error message now contains the problematic argument name:
IMO this is significantly better. I am lowering the priority (feel free to close if you think this is good enough). |
…rn types in error messages (python#18495) Fixes python#18493. Improves message in python#12013 and python#4530, but probably still doesn't make it clear enough. Use higher verbosity for type formatting in error message if callables' return types are compatible and supertype has some named arguments, as that is a popular source of confusion.
Mypy generates a confusing error for this program:
Here is the output:
The actual error is the missing argument name in the type of
y
, but the error message gives no hint about this.The text was updated successfully, but these errors were encountered: