This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: All sequence types support .index and .count
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: SilentGhost, daniel.urban, docs@python, eric.araujo, iuridiniz, rhettinger, stutzbach
Priority: normal Keywords: easy, patch

Created on 2010-09-02 19:19 by stutzbach, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
stdtypes.rst.diff SilentGhost, 2010-11-20 22:15
Messages (8)
msg115397 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-02 19:19
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 Issue9213)
msg116117 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-09-11 19:14
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).
msg121788 - (view) Author: Iuri Diniz (iuridiniz) Date: 2010-11-20 21:45
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
msg121795 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2010-11-20 22:15
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?
msg121796 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-20 22:16
Doc patch looks good.
msg121801 - (view) Author: Iuri Diniz (iuridiniz) Date: 2010-11-20 22:31
Well, I think that script not more necessary

count problem: Issue10474
msg121814 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-11-20 23:31
Patch is fine.  Go ahead and apply.
msg121821 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-21 00:46
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:

>>> for cls in str, bytes, bytearray, list, tuple, range:
...     print(cls, [method for method in set(dir(collections.Sequence)) - set(dir(cls)) if not method.startswith('_')])
... 
<class 'str'> []
<class 'bytes'> []
<class 'bytearray'> []
<class 'list'> []
<class 'tuple'> []
<class 'range'> []

Which means we can close this.  Thanks everyone!
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 53955
2010-11-21 00:46:10eric.araujosetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg121821

stage: needs patch -> resolved
2010-11-20 23:31:33rhettingersetresolution: accepted

messages: + msg121814
nosy: + rhettinger
2010-11-20 22:31:38iuridinizsetmessages: + msg121801
2010-11-20 22:16:31eric.araujosetmessages: + msg121796
2010-11-20 22:15:16SilentGhostsetfiles: + stdtypes.rst.diff

nosy: + SilentGhost
messages: + msg121795

keywords: + patch
2010-11-20 21:45:39iuridinizsetnosy: + iuridiniz
messages: + msg121788
2010-09-15 19:30:01daniel.urbansetnosy: + daniel.urban
2010-09-11 19:14:33eric.araujosetkeywords: + easy
nosy: + eric.araujo
messages: + msg116117

2010-09-02 19:19:25stutzbachcreate