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

Improve the error message for various sequences #66275

Closed
PCManticore mannequin opened this issue Jul 26, 2014 · 3 comments
Closed

Improve the error message for various sequences #66275

PCManticore mannequin opened this issue Jul 26, 2014 · 3 comments
Assignees
Labels
type-feature A feature request or enhancement

Comments

@PCManticore
Copy link
Mannequin

PCManticore mannequin commented Jul 26, 2014

BPO 22077
Nosy @terryjreedy, @PCManticore
Files
  • proper_error.patch
  • 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 = 'https://github.com/terryjreedy'
    closed_at = <Date 2014-08-02.05:32:25.890>
    created_at = <Date 2014-07-26.08:52:10.860>
    labels = ['type-feature']
    title = 'Improve the error message for various sequences'
    updated_at = <Date 2014-08-02.05:32:25.889>
    user = 'https://github.com/PCManticore'

    bugs.python.org fields:

    activity = <Date 2014-08-02.05:32:25.889>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2014-08-02.05:32:25.890>
    closer = 'terry.reedy'
    components = []
    creation = <Date 2014-07-26.08:52:10.860>
    creator = 'Claudiu.Popa'
    dependencies = []
    files = ['36104']
    hgrepos = []
    issue_num = 22077
    keywords = ['patch']
    message_count = 3.0
    messages = ['224029', '224535', '224536']
    nosy_count = 3.0
    nosy_names = ['terry.reedy', 'Claudiu.Popa', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue22077'
    versions = ['Python 3.5']

    @PCManticore
    Copy link
    Mannequin Author

    PCManticore mannequin commented Jul 26, 2014

    For a couple of sequences (bytes, list, tuple, bytearray), the error when using an invalid sequence index is misleading, because it says that only integers are allowed, while slices are allowed too.

    >>> a = []
    >>> a['python']
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: list indices must be integers, not str
    >>>

    For instance, here's how range does it:

    >>> range(1)['a']
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: range indices must be integers or slices, not str

    The attached patch improves these error messages.

    @PCManticore PCManticore mannequin added the type-feature A feature request or enhancement label Jul 26, 2014
    @terryjreedy terryjreedy self-assigned this Aug 1, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 2, 2014

    New changeset 02d6d3a7a181 by Terry Jan Reedy in branch 'default':
    Issue bpo-22077: Improve index error messages for bytearrays, bytes, lists, and
    http://hg.python.org/cpython/rev/02d6d3a7a181

    @terryjreedy
    Copy link
    Member

    while at it, I changed bytearray messages to include bad type as other do.

    @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
    type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant