Skip to content

Commit ebfaabd

Browse files
committed
Revert "Accept None as start and stop parameters for list.index() and tuple.index()"
Issue python#13340.
1 parent fd6b582 commit ebfaabd

File tree

5 files changed

+7
-39
lines changed

5 files changed

+7
-39
lines changed

Lib/test/list_tests.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,6 @@ def test_index(self):
365365
self.assertEqual(u.index(0, 3), 3)
366366
self.assertEqual(u.index(0, 3, 4), 3)
367367
self.assertRaises(ValueError, u.index, 2, 0, -10)
368-
self.assertEqual(u.index(1, None), 4)
369-
self.assertEqual(u.index(1, None, None), 4)
370-
self.assertEqual(u.index(1, 0, None), 4)
371-
self.assertEqual(u.index(1, None, 6), 4)
372-
self.assertRaises(ValueError, u.index, -1, 3)
373-
self.assertRaises(ValueError, u.index, -1, 3, None)
374-
self.assertRaises(ValueError, u.index, 1, None, 4)
375368

376369
self.assertRaises(TypeError, u.index)
377370

Lib/test/seq_tests.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,6 @@ def test_index(self):
361361
self.assertEqual(u.index(0, 3), 3)
362362
self.assertEqual(u.index(0, 3, 4), 3)
363363
self.assertRaises(ValueError, u.index, 2, 0, -10)
364-
self.assertEqual(u.index(1, None), 4)
365-
self.assertEqual(u.index(1, None, None), 4)
366-
self.assertEqual(u.index(1, 0, None), 4)
367-
self.assertEqual(u.index(1, None, 6), 4)
368-
self.assertRaises(ValueError, u.index, -1, 3)
369-
self.assertRaises(ValueError, u.index, -1, 3, None)
370-
self.assertRaises(ValueError, u.index, 1, None, 4)
371364

372365
self.assertRaises(TypeError, u.index)
373366

Misc/NEWS

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ Core and Builtins
1313
- Issue #13342: input() used to ignore sys.stdin's and sys.stdout's unicode
1414
error handler in interactive mode (when calling into PyOS_Readline()).
1515

16-
- Issue #13340: Accept None as start and stop parameters for
17-
list.index() and tuple.index().
18-
1916
- Issue #13343: Fix a SystemError when a lambda expression uses a global
2017
variable in the default value of a keyword-only argument:
2118
(lambda *, arg=GLOBAL_NAME: None)

Objects/listobject.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,20 +2109,12 @@ listindex(PyListObject *self, PyObject *args)
21092109
{
21102110
Py_ssize_t i, start=0, stop=Py_SIZE(self);
21112111
PyObject *v, *format_tuple, *err_string;
2112-
PyObject *start_obj = NULL, *stop_obj = NULL;
21132112
static PyObject *err_format = NULL;
21142113

2115-
if (!PyArg_ParseTuple(args, "O|OO:index", &v, &start_obj, &stop_obj))
2114+
if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
2115+
_PyEval_SliceIndex, &start,
2116+
_PyEval_SliceIndex, &stop))
21162117
return NULL;
2117-
2118-
if (start_obj != Py_None)
2119-
if (!_PyEval_SliceIndex(start_obj, &start))
2120-
return NULL;
2121-
2122-
if (stop_obj != Py_None)
2123-
if (!_PyEval_SliceIndex(stop_obj, &stop))
2124-
return NULL;
2125-
21262118
if (start < 0) {
21272119
start += Py_SIZE(self);
21282120
if (start < 0)

Objects/tupleobject.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -483,19 +483,12 @@ static PyObject *
483483
tupleindex(PyTupleObject *self, PyObject *args)
484484
{
485485
Py_ssize_t i, start=0, stop=Py_SIZE(self);
486-
PyObject *v, *start_obj = NULL, *stop_obj = NULL;
486+
PyObject *v;
487487

488-
if (!PyArg_ParseTuple(args, "O|OO:index", &v, &start_obj, &stop_obj))
488+
if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
489+
_PyEval_SliceIndex, &start,
490+
_PyEval_SliceIndex, &stop))
489491
return NULL;
490-
491-
if (start_obj != Py_None)
492-
if (!_PyEval_SliceIndex(start_obj, &start))
493-
return NULL;
494-
495-
if (stop_obj != Py_None)
496-
if (!_PyEval_SliceIndex(stop_obj, &stop))
497-
return NULL;
498-
499492
if (start < 0) {
500493
start += Py_SIZE(self);
501494
if (start < 0)

0 commit comments

Comments
 (0)