-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
PyList indexing: negative indices? #1667
Comments
OK, I checked all current APIs of list, tuple and sequence that take indices: Doesn't work:
Works:
Takes usize, not isize:
|
Mmm, thanks for taking the time to look at this; I'd noticed the inconsistencies but not had time to reason about them.
I would 100% support implementing
I think Python users would appreciate this. Note that if we implemented
I think the function signature should mirror possible usage, so yes,
I wonder if we can draw similar inspiration from |
OK, I'll see if I can come up with a consistent plan later. For now I'll just submit a PR that fixes the crash in |
I would rather not implement Index for So the initial plan is:
|
👍 sounds reasonable! Shall we target it for the 0.15 release so we can have some time to play around with it? |
Yes, I think that's a good plan. |
For future reference of anyone who wants to help with this proposal, see discussion in #1733. TLDR; we're going to go with using |
Note to self: I think this is a big enough change that it should go in the 0.15 migration guide. |
…et_item. NB: the behavior on out-of-range indices hasn't changed; it was merely wrongly documented before. See #1667
…rt and PyList::set_item. NB: the behavior on out-of-range indices hasn't changed; it was merely wrongly documented before. See #1667
…rt and PyList::set_item. NB: the behavior on out-of-range indices hasn't changed; it was merely wrongly documented before. See #1667
…rt and PyList::set_item. NB: the behavior on out-of-range indices hasn't changed; it was merely wrongly documented before. See #1667
PyList::get_item
andPySequence::get_item
acceptisize
indices, indicating that negative indices can be used as in Python.PyList::get_item
, however, does not support index<0 and segfaultsPyList_GetItem
.)The
assert
in there is written as if negative indices were supported.PyTuple::get_item
acceptsusize
.Also,
PySequence::get_item
returns a Result whilePyList
andPyTuple
panic on invalid indices.I see several things to think about here:
Index
for the panicing impls?get_item
should then always return a Result.PyList
support negative indices (we'd have to implement the correction ourselves)? If yes, the same should apply toPyTuple
.usize
?set_item
.I also noticed some inconsistencies of the tuple and list APIs. E.g., tuple has
slice
(and I don't meanas_slice
, it's clear that list can't have that) but list doesn't.The text was updated successfully, but these errors were encountered: