You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
range.index only takes one argument when it's documented as taking the usual 3 #79029
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2019-05-04.15:49:55.100>created_at=<Date2018-09-30.03:55:38.131>labels= ['easy', '3.8', 'type-bug', '3.7', 'docs']
title="range.index only takes one argument when it's documented as taking the usual 3"updated_at=<Date2019-05-04.15:49:55.093>user='https://github.com/mr-nfamous'
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:
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.
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.
Activity
mr-nfamous commentedon Sep 30, 2018
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...
serhiy-storchaka commentedon Sep 30, 2018
Thank you for your report Dan. It is easy to fix a docstring.
Related issues are bpo-28197 and bpo-31942.
mr-nfamous commentedon Sep 30, 2018
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:
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.
serhiy-storchaka commentedon Oct 6, 2018
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.
vstinner commentedon May 4, 2019
I merged the pull requests. Thanks.