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

range.index doesn't support start/stop optional arguments #88002

Closed
ktbarrett mannequin opened this issue Apr 14, 2021 · 4 comments
Closed

range.index doesn't support start/stop optional arguments #88002

ktbarrett mannequin opened this issue Apr 14, 2021 · 4 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ktbarrett
Copy link
Mannequin

ktbarrett mannequin commented Apr 14, 2021

BPO 43836
Nosy @mdickinson, @ammaraskar, @ktbarrett
Superseder
  • bpo-28197: Add start and stop parameters to the range.index() ABC method
  • 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 2021-04-14.18:02:32.893>
    created_at = <Date 2021-04-14.04:11:46.020>
    labels = ['type-bug', '3.8', '3.9', '3.10', '3.7', 'library']
    title = "range.index doesn't support start/stop optional arguments"
    updated_at = <Date 2021-04-14.18:02:32.891>
    user = 'https://github.com/ktbarrett'

    bugs.python.org fields:

    activity = <Date 2021-04-14.18:02:32.891>
    actor = 'ammar2'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-14.18:02:32.893>
    closer = 'ammar2'
    components = ['Library (Lib)']
    creation = <Date 2021-04-14.04:11:46.020>
    creator = 'ktbarrett'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43836
    keywords = []
    message_count = 4.0
    messages = ['391029', '391086', '391089', '391091']
    nosy_count = 3.0
    nosy_names = ['mark.dickinson', 'ammar2', 'ktbarrett']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '28197'
    type = 'behavior'
    url = 'https://bugs.python.org/issue43836'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    @ktbarrett
    Copy link
    Mannequin Author

    ktbarrett mannequin commented Apr 14, 2021

    The range builtin type is a collections.abc.Sequence, which in Python 3.5 added the optional start and stop arguments to the index method of Sequences. However, range.index does not support these optional arguments required by Sequence.

    I noticed this when creating a wrapper type around range which was a Sequence. mypy complained 'Signature of "index" incompatible with supertype "Sequence"', but attempting to pass the values raised 'TypeError: index() takes exactly one argument (3 given)'.

    @ktbarrett ktbarrett mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 14, 2021
    @mdickinson
    Copy link
    Member

    Duplicate of bpo-28197?

    @ktbarrett
    Copy link
    Mannequin Author

    ktbarrett mannequin commented Apr 14, 2021

    And so it is... There is also a PR open with a solution from 2017.
    https://github.com/python/cpython/pull/4378/files. Can this get reviewed?

    The rationalizations against solving this bug stated in the original issue are weak, range.index *is* useful. I use range objects to describe alternate indexing schemes for an array type (to model HDL datatypes that allow arbitrary indexing schemes). range.index is used to translate user supplied indexes into 0-based indexes to index into a parallel list with the array values.
    https://github.com/cocotb/cocotb/pull/2510/files#diff-62a4545e5bbb9291f2bdb820609b2d68c69cbafe64faea83beb380d01c02fb5aR315-R319

    Additionally, this causes issues with mypy. If you subclass Sequence, mypy will complain if you don't have the optional start and stop arguments in the index method. I would need to feed them into a range object in my implementation. I guess in my case I'm expected to just reject them? This breaks substitutability in my class.

    It also breaks substitutability with list, tuples, every built-in Sequence type as well.

    @ammaraskar
    Copy link
    Member

    Marked as a duplicate.

    Kaleb, would you mind posting your comment on the original bug bpo-28197?

    @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
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants