-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Incompatible types for fixed-length list/tuple creation #10606
Comments
This should be a typeshed issue. We can improve this by adding overloads for |
I think currently it is not possible to add this feature since fixed length tuples with integer generics are still a problem, see the open discussion #3345. def __mul__(self, n: SupportsIndex) -> Tuple[n *(_T_co, )]: ... is not possible yet. |
You're right. This isn't possible, not even with |
This now works correctly on master, and the resulting type is a tuple of 3 ints.
|
Confirmed as fixed in master. |
Bug Report
When creating lists or tuples of a fixed (initial) length using multiplication with a constant (i.e.
3*[1]
) mypy evaluates the type as "Tuple[XXX, ...]", even though the length of the list/tuple is known.This leads to incompatibilities when assigning values to existing variables that were constructed "classically" (i.e.
[1, 1, 1]
).I don't know if this is intentional or actually a bug.
If the type will be changed to "Tuple[XXX, XXX, XXX]" this could lead to long expressions for long lists (i.e.
1e4*[1]
).Is it possible to remove the incompatibility or will this lead to other inconsistencies?
To Reproduce
Here is a minimal example on how to reproduce the problem:
I know, that this is quite useless code, but a more often encountered code example with the same problem would be:
Expected Behavior
Both expressions should evaluate to
Tuple[int, int, int]
OR be compatible.Actual Behavior
This raises:
Incompatible types in assignment (expression has type "Tuple[int, ...]", variable has type "Tuple[int, int, int]")
Your Environment
mypy.ini
(and other config files): /Comment
I have no idea what the operation
5*(1,)
is called, so I could not find anything about this problem. Sorry, if this was asked/resolved before.The text was updated successfully, but these errors were encountered: