Skip to content

Tuple slicing is not supported #886

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
o11c opened this issue Oct 1, 2015 · 6 comments
Closed

Tuple slicing is not supported #886

o11c opened this issue Oct 1, 2015 · 6 comments
Labels
bug mypy got something wrong

Comments

@o11c
Copy link
Contributor

o11c commented Oct 1, 2015

mypy -c 'v = (1, 2, 3); major, minor = v[:2]'

<string>:1: error: Tuple index must an integer literal

Oddly, this was not a failure before I rebased my branch.

@JukkaL JukkaL added the bug mypy got something wrong label Oct 7, 2015
@JukkaL
Copy link
Collaborator

JukkaL commented Oct 7, 2015

Yeah, mypy should support this, obviously. Not sure why it got broken, though (or why it used to work).

I think that this needs to be fixed in visit_index_expr_helper (mypy/checkexpr.py).

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 10, 2015

Basic support for this is now in (by @jhance).

I'm leaving this open for now as a few additional things would be nice to have:

@jhance
Copy link
Collaborator

jhance commented Oct 10, 2015

Basically a tuple like Tuple[int, int, int] would be treated similarly to Tuple[int, ...] for slicing

I firmly believe this is evil. Having n=0 and slicing on n: would give me a different type than slicing on 0:.

Then again I hate the idea of variable-length homogenous tuples so I think my opinions on this are probably irrelevant.

@o11c
Copy link
Contributor Author

o11c commented Oct 10, 2015

There are plenty of ways to get the same object with a different type, there is nothing evil about that.

@jhance
Copy link
Collaborator

jhance commented Oct 10, 2015

Its not about the fact that I get the same object with a different type, its the fact that I'm allowed to:

  1. Do things engaging with variable-length tuples simply because it happens to be homogenous, despite non-variable-length homogenous tuples not being special in the type system.
  2. Its too easy to accidently end up with a homogenous tuple when you don't intend to. If you want this why are you not using sequence?

@o11c
Copy link
Contributor Author

o11c commented Oct 10, 2015

But even if you don't intend to get a homogenous tuple, you'll just get an error a little bit later.

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

No branches or pull requests

3 participants