Skip to content

bpo-28197: Add start and stop keywords to range.index() method#4378

Closed
nitishch wants to merge 13 commits into
python:mainfrom
nitishch:bpo-28197
Closed

bpo-28197: Add start and stop keywords to range.index() method#4378
nitishch wants to merge 13 commits into
python:mainfrom
nitishch:bpo-28197

Conversation

@nitishch
Copy link
Copy Markdown
Contributor

@nitishch nitishch commented Nov 12, 2017

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

@ktbarrett
Copy link
Copy Markdown

@nitishch Are you willing to get this rebased and ready for review again? If not I'll open an new PR and do that.

Copy link
Copy Markdown
Contributor

@shreyanavigyan shreyanavigyan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some code that requires little modifications.

Comment thread Objects/rangeobject.c
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;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
}

Comment thread Objects/rangeobject.c
}
PyObject *slice = PySlice_New(start, stop, _PyLong_One);
r = (rangeobject*) compute_slice(r, slice);
Py_DECREF(slice);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@iritkatriel
Copy link
Copy Markdown
Member

Closing as this PR is abandoned and out of date (see the issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants