[issue34848] range.index only takes one argument when it's documented as taking the usual 3
New submission from Dan Snider
range(5).index(2, 1) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: index() takes exactly one argument (2 given)
help(range.index) Help on method_descriptor:
index(...)
rangeobject.index(value, [start, [stop]]) -> integer -- return index of value.
Raise ValueError if the value is not present.
----------
assignee: docs@python
components: Argument Clinic, Documentation
messages: 326701
nosy: bup, docs@python, larry
priority: normal
severity: normal
status: open
title: range.index only takes one argument when it's documented as taking the usual 3
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker
Serhiy Storchaka
Dan Snider
s = 'abcde' s.index('d', 0, None) 3 [*s].index('d', None) Traceback (most recent call last): File "<stdin>", line 1, in <module> [*s].index('d', None) TypeError: slice indices must be integers or have an __index__ method
In 3.6.0, that error message is:
TypeError: slice indices must be integers or None or have an __index__ method
which means someone else was aware of this behavior and switched from _PyEval_SliceIndex to _PyEval_SliceIndexNotNone but didn't think these inconsistencies were inappropriate?
Anyway, I'll go ahead fix the docs later for accuracy's sake, but I'd much rather update operator.indexOf to use a new abstract api function: "PySequence_IndexOf" or some such, which is also capable of handling starting from the tail like str.rindex.
If that's something that could be done, after I finish the Python prototype of this sequence ChainMap analog and rewrite it in C, I'll have made my own abstract sequence index function which I'd happily share.
----------
_______________________________________
Python tracker
Change by Karthikeyan Singaravelan
Serhiy Storchaka
Change by Srinivas Reddy T
Change by Roundup Robot
Change by Roundup Robot
Change by miss-islington
STINNER Victor
participants (7)
-
Dan Snider
-
Karthikeyan Singaravelan
-
miss-islington
-
Roundup Robot
-
Serhiy Storchaka
-
Srinivas Reddy T
-
STINNER Victor