Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9589ab1

Browse files
committed
Revert "Accept None as start and stop parameters for list.index() and tuple.index()"
Issue #13340.
2 parents 864741b + ebfaabd commit 9589ab1

5 files changed

Lines changed: 7 additions & 39 deletions

File tree

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
@@ -16,9 +16,6 @@ Core and Builtins
1616
- Issue #13342: input() used to ignore sys.stdin's and sys.stdout's unicode
1717
error handler in interactive mode (when calling into PyOS_Readline()).
1818

19-
- Issue #13340: Accept None as start and stop parameters for
20-
list.index() and tuple.index().
21-
2219
- Issue #9896: Add start, stop, and step attributes to range objects.
2320

2421
- Issue #13343: Fix a SystemError when a lambda expression uses a global

Objects/listobject.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,19 +2122,11 @@ listindex(PyListObject *self, PyObject *args)
21222122
{
21232123
Py_ssize_t i, start=0, stop=Py_SIZE(self);
21242124
PyObject *v;
2125-
PyObject *start_obj = NULL, *stop_obj = NULL;
21262125

2127-
if (!PyArg_ParseTuple(args, "O|OO:index", &v, &start_obj, &stop_obj))
2126+
if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
2127+
_PyEval_SliceIndex, &start,
2128+
_PyEval_SliceIndex, &stop))
21282129
return NULL;
2129-
2130-
if (start_obj != Py_None)
2131-
if (!_PyEval_SliceIndex(start_obj, &start))
2132-
return NULL;
2133-
2134-
if (stop_obj != Py_None)
2135-
if (!_PyEval_SliceIndex(stop_obj, &stop))
2136-
return NULL;
2137-
21382130
if (start < 0) {
21392131
start += Py_SIZE(self);
21402132
if (start < 0)

Objects/tupleobject.c

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

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

0 commit comments

Comments
 (0)