-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Add start and stop parameters to the array.index() #76137
Comments
Sequence protocol specifies 2 optional argument for index method: array.index(value) needs start and stop arguments too. |
+1 |
Николай Спахиев: Are you only asking for the feature, or are you interested to work on a concrete patch? |
I plan to work on a patch. |
I decided to work on this, and I would like some review, as this would be my second contribution to cpython. Also, a general question: As I defined the start and end arguments Py_ssize_t, bigger indexes (more negative or more positive) than what can fit in Py_ssize_t will trigger an overflow error. This should be OK, though, as other functions with index arguments has them as Py_ssize_t - and getarrayitem() itself accepts a Py_ssize_t. Or? |
Just take list.index as an example. |
Anders Lorentsen: Py_ssize_t is the correct type for an index in the C language. It's not technically possible to create an array object larger than PY_SSIZE_T_MAX items :-) Serhiy> Just take list.index as an example. I concur with Serhiy :-) |
Writing my tests, I originally looked at Lib/test/seq_tests.py. One test case uses indexes that are (+-)4*sys.maxsize. This does not fit in Py_ssize_t, and so these tests cause my array implementation to raise an overflow exception. A solution is of course to have the function take general objects instead, and then truncate them down to a number that can fit in Py_ssize_t if it's too negative or positive). But I concur. It seems more reasonable to stay consistent with the rest of the module, too. I'll look over the test code to make sure I test for every given scenario (or as many as I can think of), and prepare a PR for this, then :) |
This functionality is useful to me. Is this issue still alive? If not, how can I help? |
As far as I can recall, the patch is generally speaking good to go. A number of discussions arose on various details, however. In any event, I'll take a look at it during the next few days. |
I have actually managed to lost my local branch of this fix, though I assume I can just start another one, manually copy over the changes, somehow mark this current PR as cancelled, aborted, or in my option the best: "replaced/superseeded by: [new PR]". In any case, there were discussions that seem to be unresolved, allow me to summarize:
---- Generally speaking: In the end, all I really did was mimic how list.index() is both written and documented, and that's when discussions about issues related to that started occurring, and so I now remember that I halted my PR, waiting for these issues to be resolved. |
I found this SO about reclaiming an orphaned pull request: But you may still need to open a new PR for it. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: