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 error message for subscripting non-generic types #91083

Closed
serhiy-storchaka opened this issue Mar 5, 2022 · 2 comments
Closed

Improve error message for subscripting non-generic types #91083

serhiy-storchaka opened this issue Mar 5, 2022 · 2 comments
Labels
3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 46927
Nosy @gvanrossum, @serhiy-storchaka, @JelleZijlstra, @Fidget-Spinner
PRs
  • bpo-46927: Include the type's name in the error message for subscripting non-generic types #31694
  • 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 2022-03-05.14:07:56.736>
    created_at = <Date 2022-03-05.10:18:42.639>
    labels = ['interpreter-core', 'type-feature', '3.11']
    title = 'Improve error message for subscripting non-generic types'
    updated_at = <Date 2022-03-05.14:07:56.735>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2022-03-05.14:07:56.735>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-03-05.14:07:56.736>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2022-03-05.10:18:42.639>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46927
    keywords = ['patch']
    message_count = 2.0
    messages = ['414573', '414576']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'serhiy.storchaka', 'JelleZijlstra', 'kj']
    pr_nums = ['31694']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue46927'
    versions = ['Python 3.11']

    @serhiy-storchaka
    Copy link
    Member Author

    Currently, if you try to subscript a non-generic type you will get an error:

    >>> int[str]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'type' object is not subscriptable

    Yes, 'type' objects are usually not subscriptable, but list[str] works, and it is not clear from the error message for what type it is failed.

    The following PR changes an error message:

    >>> int[str]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: type 'int' is not subscriptable

    @serhiy-storchaka serhiy-storchaka added 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Mar 5, 2022
    @serhiy-storchaka
    Copy link
    Member Author

    New changeset ab9301a by Serhiy Storchaka in branch 'main':
    bpo-46927: Include the type's name in the error message for subscripting non-generic types (GH-31694)
    ab9301a

    @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.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant