[issue9746] All sequence types support .index and .count
New submission from Daniel Stutzbach <daniel@stutzbachenterprises.com>: 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) ---------- assignee: docs@python components: Documentation messages: 115397 nosy: docs@python, stutzbach priority: normal severity: normal stage: needs patch status: open title: All sequence types support .index and .count type: behavior versions: Python 2.7, Python 3.1, Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9746> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: 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). ---------- keywords: +easy nosy: +eric.araujo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9746> _______________________________________
Changes by Daniel Urban <urban.dani+py@gmail.com>: ---------- nosy: +durban _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9746> _______________________________________
Iuri Diniz <iuridiniz@gmail.com> added the comment: 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 ---------- nosy: +iuridiniz _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9746> _______________________________________
SilentGhost <michael.mischurow+bpo@gmail.com> added the comment: 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? ---------- keywords: +patch nosy: +SilentGhost Added file: http://bugs.python.org/file19715/stdtypes.rst.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9746> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: Doc patch looks good. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9746> _______________________________________
Iuri Diniz <iuridiniz@gmail.com> added the comment: Well, I think that script not more necessary count problem: Issue10474 ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9746> _______________________________________
Raymond Hettinger <rhettinger@users.sourceforge.net> added the comment: Patch is fine. Go ahead and apply. ---------- nosy: +rhettinger resolution: -> accepted _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9746> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: 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! ---------- resolution: accepted -> fixed stage: needs patch -> committed/rejected status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9746> _______________________________________
participants (6)
-
Daniel Stutzbach
-
Daniel Urban
-
Iuri Diniz
-
Raymond Hettinger
-
SilentGhost
-
Éric Araujo