-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Allow non-literals when indexing uniform tuples #899
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
Comments
The relevant bit of code is |
I think there's a good argument for allowing it for all tuples, just with a return type of Rather than forcing the error immediately, let the error be deferred if necessary. |
Also fix the defaults for start, end, and stride to `None` to correctly match the Python slice semantics -- in particular, if the stride is negative then the default start and end are effectively `length - 1` and `0` respectively rather than vice versa. Fixes #886, except for the part that's been separated out as #899.
I had a generator expression that constructed a tuple, that I knew from context would be of length 3
And then later
There were two mypy errors:
The first is easier to understand, the latter I found very confusing because it went away as soon as I typed the tuple-generator exception without a specific length, e.g. |
Currently mypy doesn't allow indexing fixed-length tuples using a non-literal index. We should probably support this at least for tuples with homogeneous types.
For example, code like this should probably be okay:
The example below is actually already valid so rejecting the above code is inconsistent (this works due to how we set the
fallback
attribute for tuples to beTuple[t, ...]
):The text was updated successfully, but these errors were encountered: