-
-
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
(🐞) False positive "error: Type application has too many types (1 expected)" on tuple when annotated as a type or in a TypeAlias
with new union syntax (PEP 604)
#11098
Comments
Also |
Still happening with mypy 0.931 in .pyi files:
Could potentially be fixed by #11915. This too is a blocker for using new union syntax everywhere in typeshed. |
Yeah, looks like it could be fixed by #11915. I now have a minimal repro for the case that motivated that one, but I'm still working on incorporating the repro into mypy's test suite. I'll try to test whether my proposed stub-only fix also fixes this case, and add a regression test for it, if so. |
I have just tested this, and it appears that this is not fixed by #11915, sadly. (@sobolevn, @hauntsaninja, any idea about what the cause of this might be?) |
Here is a failing test that is ready to be integrated into mypy's test suite, if it is helpful:
This fails with:
So mypy appears able to infer the type just fine, but nonetheless raises the spurious "Type application has too many types" error message. |
Error is happening in a different, later place of the type checker. Quickest fix is probably special casing |
Whats the deal with contributing xfail tests? I could add a whole heap from issues I've raised, is that useful at all? |
(just speaking for myself) I think of them as basically a better TODO comment. |
So if I made some PRs, only adding xfails from issues I've raised, they would be appreciated? |
To be clear, I wasn't suggesting that the test case I was providing above should be integrated into the test suite now, without a fix for the issue; I just thought it might be helpful to someone else, if they wanted to work on a fix. The mypy test suite is a slightly different environment to running mypy normally, so it's not always as easy to reproduce something in the test suite as it is in mypy playground. |
I haven't really looked into this, but I imagine xfail tests are prone to failing for the wrong reason. We frequently make big changes to our test suite when some wording changes a little, so chances are xfail tests will rapidly start failing not because of the actual bug but because the test says "builtins.int" instead of "int". |
I've submitted #12134 |
@KotlinIsland you changed the title of this issue yesterday but the title now refers to the wrong PEP. You want 604, not 406. |
TypeAlias
with new union syntax (PEP 604)
Fix type aliases like these: ``` T = tuple[int, str] ``` Type applications involving fixed-length tuples still don't fully work. The inferred type is a variable-length tuple when constructing a tuple using a type application, e.g. `tuple[int, str]((1, ""))`. This seems a pretty low-priority issue, whereas the type alias use case seems common. Most of the work was by @sobolevn originally in #12134. I just finished it up. Fixes #11098.
mypy 0.910
also on functions attributes:
also when in a new union syntax type alias:
https://mypy-play.net/?mypy=latest&python=3.10&flags=strict%2Ccheck-untyped-defs%2Cdisallow-any-decorated%2Cdisallow-any-expr%2Cdisallow-any-explicit%2Cdisallow-any-generics%2Cdisallow-any-unimported%2Cdisallow-incomplete-defs%2Cdisallow-subclassing-any%2Cdisallow-untyped-calls%2Cdisallow-untyped-decorators%2Cdisallow-untyped-defs%2Cwarn-incomplete-stub%2Cwarn-redundant-casts%2Cwarn-return-any%2Cwarn-unreachable%2Cwarn-unused-configs%2Cwarn-unused-ignores&gist=9604ab8dfb68e31788348b8ea36b54a1
The text was updated successfully, but these errors were encountered: