-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
We should have a type for variable-length tuples. It could be called TupleSequence[T]
.
Example:
t = None # type: Tuple[int, ...]
t = (1, 2) # Okay
t = (1, 2, 3) # Okay
n = 1
print(t[n]) # Okay
for n in t: print(n) # Okay
t = [1, 2] # Error
It is needed for precise static typing of some builtins, such as str.startswith
.
We would not (generally) infer these types automatically for variables: type inference would still produce Tuple[...]
types.
Update: Actually, it seems more reasonable to have Tuple[...] as a subtype of TupleSequence[...] assuming type arguments are compatible. Also need to update type joins to handle these.
EDIT: Update to conform to the actual syntax.
neighthan, amrit3701, fzyzcjy and y2k-shubham