[issue34848] range.index only takes one argument when it's documented as taking the usual 3

New submission from Dan Snider <mr.assume.away@gmail.com>: 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. ---------- 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 <report@bugs.python.org> <https://bugs.python.org/issue34848> _______________________________________

Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment: Thank you for your report Dan. It is easy to fix a docstring. Related issues are issue28197 and issue31942. ---------- components: -Argument Clinic keywords: +easy (C) nosy: +rhettinger, serhiy.storchaka -larry stage: -> needs patch type: -> behavior versions: +Python 3.8 -Python 3.4, Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34848> _______________________________________

Dan Snider <mr.assume.away@gmail.com> added the comment: 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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34848> _______________________________________

Change by Karthikeyan Singaravelan <tir.karthi@gmail.com>: ---------- nosy: +xtreak _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34848> _______________________________________

Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment: 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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34848> _______________________________________

Change by Srinivas Reddy T <thatiparthysreenivas@gmail.com>: ---------- keywords: +patch pull_requests: +9240 stage: needs patch -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34848> _______________________________________

Change by Roundup Robot <devnull@psf.upfronthosting.co.za>: ---------- pull_requests: +9243 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34848> _______________________________________

Change by Roundup Robot <devnull@psf.upfronthosting.co.za>: ---------- pull_requests: +9244 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34848> _______________________________________

Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +12989 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34848> _______________________________________

STINNER Victor <vstinner@redhat.com> added the comment: I merged the pull requests. Thanks. ---------- nosy: +vstinner resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34848> _______________________________________
participants (7)
-
Dan Snider
-
Karthikeyan Singaravelan
-
miss-islington
-
Roundup Robot
-
Serhiy Storchaka
-
Srinivas Reddy T
-
STINNER Victor