Skip to content

Add type for variable-length tuples #184

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

Closed
JukkaL opened this issue Jul 4, 2013 · 4 comments
Closed

Add type for variable-length tuples #184

JukkaL opened this issue Jul 4, 2013 · 4 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 4, 2013

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.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 17, 2015

PEP 484 draft uses Tuple[int, ...] (the dots are part of the syntax), which seems pretty reasonable and better than TupleSequence: python/typing#30

It will also work in Python 2.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Aug 31, 2015

There are still some corner cases that aren't handled properly, but I pushed the implementation as it's good enough for many uses already.

@o11c
Copy link
Contributor

o11c commented Aug 31, 2015

Now to change all the stubs ...

@JukkaL
Copy link
Collaborator Author

JukkaL commented Sep 1, 2015

I updated some obvious stub definitions already (startswith etc.), but I'm sure I missed a bunch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants