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
More specifically, I think the root cause is that we don't properly perform union math on functions containing TypeVars with value restrictions:
from typing import TypeVar, Union
T = TypeVar('T', int, str)
def test(x: T) -> T:
return x
y: Union[int, str]
test(y)
We get a Value of type variable "T" of "test" cannot be "Union[int, str]" error on the final line, which I think is suboptimal -- test is morally equivalent to an overload, and we'd accept a call of test(Union[int, str]) if the signature was written as such.
(Note that shutil.copyfile(...) accepts a TypeVar with value restriction for the second arg, and fails when passed a union.)
...it's a little surprising to me that we don't have an issue for this already, actually. I tried searching for one before suggesting OP file an issue here, but no dice.
I have this code which was accepted in a older version (0.6xx?) of mypy:
But is not accepted by mypy 0.710:
How should I fix my type annotations?
I tried this:
And that seems to work.
I asked this on StackOverflow but it was suggested to open a "bug/missing feature issue" here.
The text was updated successfully, but these errors were encountered: