Skip to content

Add type for variable-length tuples #184

@JukkaL

Description

@JukkaL

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions