[New-bugs-announce] [issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

Raymond Hettinger report at bugs.python.org
Thu Dec 18 21:41:46 CET 2014


New submission from Raymond Hettinger:

Currently, the Sequence ABC doesn't support start and stop arguments for the index() method which limits its usefulness in doing repeated searches (iterating over a target value) and which limits it substitutablity for various concrete sequences such as tuples, lists, strings, bytes, bytearrays, etc.

>>> help(Sequence.index)
Help on method index in module _abcoll:

index(self, value) unbound _abcoll.Sequence method
    S.index(value) -> integer -- return first index of value.
    Raises ValueError if the value is not present.

>>> help(list.index)
Help on method_descriptor:

index(...)
    L.index(value, [start, [stop]]) -> integer -- return first index of value.
    Raises ValueError if the value is not present.

>>> help(str.index)
Help on method_descriptor:

index(...)
    S.index(sub [,start [,end]]) -> int
    
    Like S.find() but raise ValueError when the substring is not found.

>>> help(tuple.index)
Help on method_descriptor:

index(...)
    T.index(value, [start, [stop]]) -> integer -- return first index of value.
    Raises ValueError if the value is not present.

>>> help(bytes.index)
Help on method_descriptor:

index(...)
    S.index(sub [,start [,end]]) -> int
    
    Like S.find() but raise ValueError when the substring is not found.

>>> help(bytearray.index)
Help on method_descriptor:

index(...)
    B.index(sub [,start [,end]]) -> int
    
    Like B.find() but raise ValueError when the subsection is not found.

----------
assignee: rhettinger
components: Library (Lib)
messages: 232904
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Add start and stop parameters to the Sequence.index() ABC mixin method
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23086>
_______________________________________


More information about the New-bugs-announce mailing list