Skip to content

range.index only takes one argument when it's documented as taking the usual 3 #79029

Closed

Description

@mr-nfamous
BPO 34848
Nosy @rhettinger, @vstinner, @serhiy-storchaka, @mr-nfamous, @tirkarthi
PRs
  • bpo-34848 : Correct a method signature in docstring for range(..).index method #9877
  • removing documentation bug as per Issue34848 #9880
  • bpo-34848: Changed rangeobject docstring for index. Current docstring says user can pass in multiple args when only 2 args are supported. #9881
  • [3.7] bpo-34848 : Correct an incorrect docstring for range().index method (GH-9877) #13075
  • 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 2019-05-04.15:49:55.100>
    created_at = <Date 2018-09-30.03:55:38.131>
    labels = ['easy', '3.8', 'type-bug', '3.7', 'docs']
    title = "range.index only takes one argument when it's documented as taking the usual 3"
    updated_at = <Date 2019-05-04.15:49:55.093>
    user = 'https://github.com/mr-nfamous'

    bugs.python.org fields:

    activity = <Date 2019-05-04.15:49:55.093>
    actor = 'vstinner'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2019-05-04.15:49:55.100>
    closer = 'vstinner'
    components = ['Documentation']
    creation = <Date 2018-09-30.03:55:38.131>
    creator = 'bup'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34848
    keywords = ['patch', 'easy (C)']
    message_count = 5.0
    messages = ['326701', '326704', '326746', '327242', '341390']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'vstinner', 'docs@python', 'serhiy.storchaka', 'bup', 'xtreak']
    pr_nums = ['9877', '9880', '9881', '13075']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34848'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    Activity

    1. mr-nfamous commented on Sep 30, 2018

      mr-nfamousmannequin
      MannequinAuthor

      Unfortunately, it looks like there's no requirement for an abc.Sequence to implement the 3 argument form of seq.index, so I suppose this is technically just a documentation bug...

      >>> range(5).index(2, 1)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: index() takes exactly one argument (2 given)
      
      >>> help(range.index)
      Help on method_descriptor:
      index(...)
          rangeobject.index(value, [start, [stop]]) -> integer -- return index of value.
          Raise ValueError if the value is not present.
    2. added
      docs
      on Sep 30, 2018
    3. serhiy-storchaka commented on Sep 30, 2018

      @serhiy-storchaka
      Member

      Thank you for your report Dan. It is easy to fix a docstring.

      Related issues are bpo-28197 and bpo-31942.

    4. added
      3.8 (EOL)
      type-bug
      and removed on Sep 30, 2018
    5. mr-nfamous commented on Sep 30, 2018

      mr-nfamousmannequin
      MannequinAuthor

      So I also just happened to notice that the "documentation is wrong" for list, tuple, and collections.deque. They use use _PyEval_SliceIndexNotNone whch causes this:

      >>> s = 'abcde'
      >>> s.index('d', 0, None)
      3
      >>> [*s].index('d', None)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
          [*s].index('d', None)
      TypeError: slice indices must be integers or have an __index__ method

      In 3.6.0, that error message is:
      TypeError: slice indices must be integers or None or have an __index__ method

      which means someone else was aware of this behavior and switched from _PyEval_SliceIndex to _PyEval_SliceIndexNotNone but didn't think these inconsistencies were inappropriate?

      Anyway, I'll go ahead fix the docs later for accuracy's sake, but I'd much rather update operator.indexOf to use a new abstract api function: "PySequence_IndexOf" or some such, which is also capable of handling starting from the tail like str.rindex.

      If that's something that could be done, after I finish the Python prototype of this sequence ChainMap analog and rewrite it in C, I'll have made my own abstract sequence index function which I'd happily share.

    6. serhiy-storchaka commented on Oct 6, 2018

      @serhiy-storchaka
      Member

      One bug or feature request per issue please. If you want to change list.index() or operator.indexOf(), open new issues for this. This issue is for the error in the range.index() docstring.

    7. vstinner commented on May 4, 2019

      @vstinner
      Member

      I merged the pull requests. Thanks.

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)3.8 (EOL)docseasytype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions