Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All sequence types support .index and .count #53955

Closed
stutzbach mannequin opened this issue Sep 2, 2010 · 8 comments
Closed

All sequence types support .index and .count #53955

stutzbach mannequin opened this issue Sep 2, 2010 · 8 comments
Labels
docs Documentation in the Doc dir easy type-bug An unexpected behavior, bug, or error

Comments

@stutzbach
Copy link
Mannequin

stutzbach mannequin commented Sep 2, 2010

BPO 9746
Nosy @rhettinger, @merwok, @durban
Files
  • stdtypes.rst.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2010-11-21.00:46:10.114>
    created_at = <Date 2010-09-02.19:19:24.982>
    labels = ['easy', 'type-bug', 'docs']
    title = 'All sequence types support .index and .count'
    updated_at = <Date 2010-11-21.00:46:10.113>
    user = 'https://bugs.python.org/stutzbach'

    bugs.python.org fields:

    activity = <Date 2010-11-21.00:46:10.113>
    actor = 'eric.araujo'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2010-11-21.00:46:10.114>
    closer = 'eric.araujo'
    components = ['Documentation']
    creation = <Date 2010-09-02.19:19:24.982>
    creator = 'stutzbach'
    dependencies = []
    files = ['19715']
    hgrepos = []
    issue_num = 9746
    keywords = ['patch', 'easy']
    message_count = 8.0
    messages = ['115397', '116117', '121788', '121795', '121796', '121801', '121814', '121821']
    nosy_count = 7.0
    nosy_names = ['rhettinger', 'stutzbach', 'eric.araujo', 'SilentGhost', 'daniel.urban', 'docs@python', 'iuridiniz']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue9746'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @stutzbach
    Copy link
    Mannequin Author

    stutzbach mannequin commented 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)

    @stutzbach stutzbach mannequin assigned docspython Sep 2, 2010
    @stutzbach stutzbach mannequin added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error labels Sep 2, 2010
    @merwok
    Copy link
    Member

    merwok commented 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).

    @merwok merwok added the easy label Sep 11, 2010
    @iuridiniz
    Copy link
    Mannequin

    iuridiniz mannequin commented 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
    Copy link
    Mannequin

    SilentGhost mannequin commented 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
    Copy link
    Member

    merwok commented Nov 20, 2010

    Doc patch looks good.

    @iuridiniz
    Copy link
    Mannequin

    iuridiniz mannequin commented Nov 20, 2010

    Well, I think that script not more necessary

    count problem: bpo-10474

    @rhettinger
    Copy link
    Contributor

    Patch is fine. Go ahead and apply.

    @merwok
    Copy link
    Member

    merwok commented 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:

    >>> 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!

    @merwok merwok closed this as completed Nov 21, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir easy type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants