Home > Back-end >  list[int, ...] is not working while tuple[int, ...] is working while i'm using mypy . Please ex
list[int, ...] is not working while tuple[int, ...] is working while i'm using mypy . Please ex

Time:07-10

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
  1. 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.

  • Related