-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Type inference problems with unions, overloads and map #390
Comments
Thanks for reporting this! There are at least a few known type inference related bugs and this could be one of these or a related issue. They tend to revolve around overloading and higher-order functions. I'm going to look at them one of these days once things settle down a bit... |
Added issue #495 derived from the first example. |
Added issue #496 derived from the second example. |
This is still failing (updated to use the current syntax): from typing import List, Union, overload
def f(x: Union[List[int], List[str]]) -> None:
l = map(f, x) # Cannot infer type argument 1 of "map"
@overload
def f(x: int) -> List[int]: ...
@overload
def f(x: str) -> List[str]: ...
def f(x):
return [x] |
@Michael0x2a I think this might be a good test for your union math PR. |
Both examples pass on current master (most likely because of union math). |
I'm playing with mypy, trying to do some things, and I've getted some strange behaviour (I think).
I'm trying to do a function that takes a list and then apply map function. The trick is that the list can be of two different types.
The first try was something like that:
The fail that getted was this one:
Then, I tried to do it with a typevar:
And now I've getted that error:
If I add the function that 'mypy' says:
And now the typecheck pass.
If I write the overloaded functions backwards, mypy expects other thing:
Expected:
I don't really know why that's going on, but I think that is a strange behaviour :)
The text was updated successfully, but these errors were encountered: