Skip to content

bpo-31942: Document optional support of start and stop attributes in Sequence.index method #4277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,9 @@ Notes:

(8)
``index`` raises :exc:`ValueError` when *x* is not found in *s*.
When supported, the additional arguments to the index method allow
efficient searching of subsections of the sequence. Passing the extra
arguments is roughly equivalent to using ``s[i:j].index(x)``, only
Not all implementations support passing the additional arguments *i* and *j*.
These arguments allow efficient searching of subsections of the sequence. Passing
the extra arguments is roughly equivalent to using ``s[i:j].index(x)``, only
without copying any data and with the returned index being relative to
the start of the sequence rather than the start of the slice.

Expand Down
3 changes: 3 additions & 0 deletions Lib/_collections_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,9 @@ def __reversed__(self):
def index(self, value, start=0, stop=None):
'''S.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but
recommended.
'''
if start is not None and start < 0:
start = max(len(self) + start, 0)
Expand Down