a: list[int, ...] = [1,2,3,4,5]
print(a) # i am getting error while running on mypy
b: tuple[int, ...] = (1,2,3,4,5)
print(b) # runs without error on mypy
- Please Explain why mypy raises error on list but not on tuple ?
CodePudding user response:
tuple[T, ...]
means a tuple of any length of elements of type T
.
There is no such construct for list
as lists are homogenous. list
accepts only one type parameter that specifies the list element type.
CodePudding user response:
If you wish to specify a list of integers use list[int]
instead of list[int, ...]
.
There is no ellipsis (...
) for lists.
For more info, see the documentation.