classification
Title: range.index only takes one argument when it's documented as taking the usual 3
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: bup, docs@python, rhettinger, serhiy.storchaka, vstinner, xtreak
Priority: normal Keywords: easy (C), patch

Created on 2018-09-30 03:55 by bup, last changed 2019-05-04 15:49 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9877 merged thatiparthy, 2018-10-14 18:55
PR 9880 closed python-dev, 2018-10-14 21:05
PR 9881 closed python-dev, 2018-10-14 21:18
PR 13075 merged miss-islington, 2019-05-03 12:25
Messages (5)
msg326701 - (view) Author: Dan Snider (bup) * Date: 2018-09-30 03:55
Unfortunately, it looks like there's no requirement for an abc.Sequence to implement the 3 argument form of seq.index, so I suppose this is technically just a documentation bug...

>>> 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.
msg326704 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-09-30 06:02
Thank you for your report Dan. It is easy to fix a docstring.

Related issues are issue28197 and issue31942.
msg326746 - (view) Author: Dan Snider (bup) * Date: 2018-09-30 20:54
So I also just happened to notice that the "documentation is wrong" for list, tuple, and collections.deque. They use use _PyEval_SliceIndexNotNone whch causes this:

>>> 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.
msg327242 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-06 12:03
One bug or feature request per issue please. If you want to change list.index() or operator.indexOf(), open new issues for this. This issue is for the error in the range.index() docstring.
msg341390 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-04 15:49
I merged the pull requests. Thanks.
History
Date User Action Args
2019-05-04 15:49:55vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg341390

resolution: fixed
stage: patch review -> resolved
2019-05-03 12:25:17miss-islingtonsetpull_requests: + pull_request12989
2018-10-14 21:18:03python-devsetpull_requests: + pull_request9244
2018-10-14 21:05:45python-devsetpull_requests: + pull_request9243
2018-10-14 18:55:45thatiparthysetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request9240
2018-10-06 12:03:47serhiy.storchakasetmessages: + msg327242
2018-10-06 11:49:14xtreaksetnosy: + xtreak
2018-09-30 20:54:25bupsetmessages: + msg326746
2018-09-30 06:02:51serhiy.storchakasettype: behavior
components: - Argument Clinic
versions: + Python 3.8, - Python 3.4, Python 3.5
keywords: + easy (C)
nosy: + rhettinger, serhiy.storchaka, - larry

messages: + msg326704
stage: needs patch
2018-09-30 03:55:38bupcreate