bpo-28197: Add start and stop keywords to range.index() method#4378
Closed
nitishch wants to merge 13 commits into
Closed
bpo-28197: Add start and stop keywords to range.index() method#4378nitishch wants to merge 13 commits into
nitishch wants to merge 13 commits into
Conversation
|
@nitishch Are you willing to get this rebased and ready for review again? If not I'll open an new PR and do that. |
shreyanavigyan
suggested changes
Apr 14, 2021
Contributor
shreyanavigyan
left a comment
There was a problem hiding this comment.
Found some code that requires little modifications.
Comment on lines
+547
to
+562
| if(start){ | ||
| if(!PyLong_CheckExact(start)){ | ||
| PyErr_Format(PyExc_TypeError, | ||
| "start value must be integer, not %.200s", | ||
| start->ob_type->tp_name); | ||
| return NULL; | ||
| } | ||
| } | ||
| if(stop){ | ||
| if(!PyLong_CheckExact(stop)){ | ||
| PyErr_Format(PyExc_TypeError, | ||
| "stop value must be integer, not %.200s", | ||
| stop->ob_type->tp_name); | ||
| return NULL; | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Make the code look a little bit cleaner.
Suggested change
| if(start){ | |
| if(!PyLong_CheckExact(start)){ | |
| PyErr_Format(PyExc_TypeError, | |
| "start value must be integer, not %.200s", | |
| start->ob_type->tp_name); | |
| return NULL; | |
| } | |
| } | |
| if(stop){ | |
| if(!PyLong_CheckExact(stop)){ | |
| PyErr_Format(PyExc_TypeError, | |
| "stop value must be integer, not %.200s", | |
| stop->ob_type->tp_name); | |
| return NULL; | |
| } | |
| } | |
| if(start && (!PyLong_CheckExact(start))){ | |
| PyErr_Format(PyExc_TypeError, | |
| "start value must be integer, not %.200s", | |
| start->ob_type->tp_name); | |
| return NULL; | |
| } | |
| if(stop && (!PyLong_CheckExact(stop))){ | |
| PyErr_Format(PyExc_TypeError, | |
| "stop value must be integer, not %.200s", | |
| stop->ob_type->tp_name); | |
| return NULL; | |
| } |
| } | ||
| PyObject *slice = PySlice_New(start, stop, _PyLong_One); | ||
| r = (rangeobject*) compute_slice(r, slice); | ||
| Py_DECREF(slice); |
Contributor
There was a problem hiding this comment.
Slice object creation maybe unsuccessful in which case the return value maybe NULL. Therefore use Py_XDECREF.
Suggested change
| Py_DECREF(slice); | |
| Py_XDECREF(slice); |
|
This PR is stale because it has been open for 30 days with no activity. |
Member
|
Closing as this PR is abandoned and out of date (see the issue). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added start and stop as keywords to range.index method.
I created a temporary range object on which indexing will be done. Is there a better way to decref the temporary range object?
https://bugs.python.org/issue28197