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

(cherry picked from commit 5ce0a2a100)
This commit is contained in:
Miss Islington (bot) 2017-12-12 02:58:26 -08:00 committed by Victor Stinner
parent ce5a3cd9b1
commit 78cd00b799
2 changed files with 6 additions and 3 deletions

View file

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

View file

@ -899,6 +899,9 @@ class Sequence(Reversible, Collection):
def index(self, value, start=0, stop=None): def index(self, value, start=0, stop=None):
'''S.index(value, [start, [stop]]) -> integer -- return first index of value. '''S.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present. 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: if start is not None and start < 0:
start = max(len(self) + start, 0) start = max(len(self) + start, 0)