Skip to content

Add support for tuple slices. #895

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

Merged
merged 2 commits into from
Oct 9, 2015
Merged

Add support for tuple slices. #895

merged 2 commits into from
Oct 9, 2015

Conversation

jhance
Copy link
Collaborator

@jhance jhance commented Oct 8, 2015

Apparently python happily accepts any slice, even if its
out of range (and just gives an empty tuple). Personally,
I find that behavior weird, but I opted to not check any
ranges because python itself doesn't care.
#886

jhance added 2 commits October 8, 2015 13:53
Apparently python happily accepts any slice, even if its
out of range (and just gives an empty tuple). Personally,
I find that behavior weird, but I opted to not check any
ranges because python itself doesn't care.
@o11c
Copy link
Contributor

o11c commented Oct 9, 2015

Looks like you're missing Tuple[T, ...].

@o11c
Copy link
Contributor

o11c commented Oct 9, 2015

Homogenous tuples (of either kind) should support non-literal slices.

@jhance
Copy link
Collaborator Author

jhance commented Oct 9, 2015

No they shouldn't, you lose the length of the tuple if you don't have a literal slice. I can see an argument for them resolving to variable-length tuples, but I dislike it.

I don't mind having homogenous tuples work with arbitrary slices, though.

I'll probably get homogenous tuples working tomorrow, I thought it would be simple but for some reason its treating it like not-a-tuple...

@o11c
Copy link
Contributor

o11c commented Oct 9, 2015

It was really screwy to me at first, how the type shows up internally as builtins.tuple[T], not typing.Tuple[T, ...].

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 9, 2015

Cool, thanks for the PR!

Slicing of Tuple[t, ...] values already works. They are internally regular classes and support methods defined in buildins.tuple, including __getitem__ with a slice argument.

Slicing homogeneous, fixed-length tuples like Tuple[int, int, int] with non-literal slices could be valid. Similarly, we should probably support indexing them with non-literal integers (e.g., t[n]).

One another thing would be nice to support: negative literal int in slice (e.g., t[:-1]).

JukkaL added a commit that referenced this pull request Oct 9, 2015
Add support for tuple slices.
@JukkaL JukkaL merged commit 1a5d982 into python:master Oct 9, 2015
@jhance
Copy link
Collaborator Author

jhance commented Oct 9, 2015

Slicing of Tuple[t, ...] values already works. They are internally regular classes and support methods defined in buildins.tuple, including getitem with a slice argument.

FYI I was seeing mypy crash failing to locate the name slice when I so much as added a slice of Tuple[T, ...] to the test file.

@o11c
Copy link
Contributor

o11c commented Oct 9, 2015

That's because of #890

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

Successfully merging this pull request may close these issues.

3 participants