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
All sequence types support .index and .count #53955
In the list of operations supported by all sequence types, the .index and .count methods should be included. They are defined by the collections.Sequence ABC that all sequences support.
(except for range objects, but that will be fixed in bpo-9213)
For the person wanting to make a patch: Beware that the abstract collections.Sequence.index method does not support the start and stop arguments, even though concrete methods may (list.index, tuple.index and str.index for example).
I have checked that only bytearray, bytes, list, range, str and tuple are valid sequence types [using issubclass(type, collections.Sequence)] and all of them has index and count methods...
I'm working on a script to discovery what types that are not collections.Sequence ABC yet, but must be.
Merwork said the docs are the authoritative reference to define what classes are sequences and one way to discovery it is by comparing the set of methods of each concrete class with the methods of collections.Sequence
Activity
stutzbach commentedon Sep 2, 2010
In the list of operations supported by all sequence types, the .index and .count methods should be included. They are defined by the collections.Sequence ABC that all sequences support.
(except for range objects, but that will be fixed in bpo-9213)
merwok commentedon Sep 11, 2010
For the person wanting to make a patch: Beware that the abstract collections.Sequence.index method does not support the start and stop arguments, even though concrete methods may (list.index, tuple.index and str.index for example).
iuridiniz commentedon Nov 20, 2010
Is this bug valid?
I have checked that only bytearray, bytes, list, range, str and tuple are valid sequence types [using issubclass(type, collections.Sequence)] and all of them has index and count methods...
I'm working on a script to discovery what types that are not collections.Sequence ABC yet, but must be.
Merwork said the docs are the authoritative reference to define what classes are sequences and one way to discovery it is by comparing the set of methods of each concrete class with the methods of collections.Sequence
SilentGhost commentedon Nov 20, 2010
Here is the patch for the table in Doc/library/stdtypes.rst
.count on range by some reason returns a boolean. Should it not be an int?
merwok commentedon Nov 20, 2010
Doc patch looks good.
iuridiniz commentedon Nov 20, 2010
Well, I think that script not more necessary
count problem: bpo-10474
rhettinger commentedon Nov 20, 2010
Patch is fine. Go ahead and apply.
merwok commentedon Nov 21, 2010
Patch committed in r86625 (py3k), r86627 (3.1) and r86627 (2.7).
Regarding API conformance, I ran this simple test, courtesy of Daniel in msg109784:
Which means we can close this. Thanks everyone!