Skip to content
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

Keyword names in callable args not surfaced in error messages #5444

Closed
msullivan opened this issue Aug 9, 2018 · 1 comment
Closed

Keyword names in callable args not surfaced in error messages #5444

msullivan opened this issue Aug 9, 2018 · 1 comment
Labels
bug mypy got something wrong

Comments

@msullivan
Copy link
Collaborator

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
Argument 1 to "oops" has incompatible type "List[Callable[[int], None]]"; expected "List[Callable[[int], None]]", followed by some advice about covariance. The astute observer will note that those types are exactly the same.

Digging a bit deeper with reveal_type, though, gives us that funcs actually has the more precise type
builtins.list[def (x: builtins.int)], which includes the argument name.

So what is happening here is that we are inferring the type of the list of functions to include the name of the function argument, which then produces an error when passed to oops because List is invariant. It is perhaps debatable whether we want to be inferring a type like that in this situation. We definitely want to produce a better error message when we do.

@msullivan msullivan added the bug mypy got something wrong label Aug 9, 2018
@ilevkivskyi
Copy link
Member

This is essentially a duplicate of #4530 (already high priority). I would propose to close this one. I will copy the example to the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants