-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Overloads with type variables and generic types are incorrectly rejected #9420
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
Methinks (and mypy agrees :-) that the return value should be declared as If you put something in the function that returns an appropriate value (e.g. But perhaps your real-world use case was different? |
Yes, my real use case was with an invariant generic - in that case So, changing from
and the error is:
This code seems wrong to me though, and the error seems right, |
Also I should note that if I only change Tuple to List in the original reproducer, with the return type being |
Indeed, in your second example the problem is that So I agree there is something to your first example. What to do about it? I would just return Any from the implementation. Mypy in general does not check that an overload implementation is correct. |
Interesting, I would have assumed that mypy checks an overload implementation like a normal function, ignoring the overloads. In any case, if I just return
But if I take
Then it works fine. It seems a little unfortunate to have to do that, but at least the overloads work for the user. I might just tag it |
The original example now type-checks cleanly on master. While the second example gives:
I would propose to close this, we can track the second example (but also TBH it's in a gray area) in #11391 |
🐛 Bug Report
If there are multiple overloads for a function, each of which take different type variables, and which return a generic type parameterized on the type variable, mypy will incorrectly report that the overload is incorrect.
To Reproduce
Expected Behavior
mypy succeeds with no errors.
Actual Behavior
mypy fails with
The same error message is printed also with the
Foo
/Bar
bounds removed, plus an error about overlapping overloads. So I don't think the bounds are an essential part.If I remove the Tuple wrapping the return values, it succeeds.
Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: