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

ast.parse with type_comments=True should allow extra text after # type: ignore #81059

Closed
msullivan mannequin opened this issue May 10, 2019 · 9 comments
Closed

ast.parse with type_comments=True should allow extra text after # type: ignore #81059

msullivan mannequin opened this issue May 10, 2019 · 9 comments
Labels
3.8 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@msullivan
Copy link
Mannequin

msullivan mannequin commented May 10, 2019

BPO 36878
Nosy @gvanrossum, @ilevkivskyi, @miss-islington, @msullivan
PRs
  • bpo-36878: Allow extra text after # type: ignore comments #13238
  • bpo-36878: Track extra text added to 'type: ignore' in the AST #13479
  • bpo-36878: Only allow text after # type: ignore if first character ASCII #13504
  • 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-22.21:08:33.760>
    created_at = <Date 2019-05-10.20:40:16.492>
    labels = ['interpreter-core', 'type-feature', '3.8']
    title = 'ast.parse with type_comments=True should allow extra text after # type: ignore'
    updated_at = <Date 2019-05-22.21:28:13.436>
    user = 'https://github.com/msullivan'

    bugs.python.org fields:

    activity = <Date 2019-05-22.21:28:13.436>
    actor = 'msullivan'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-22.21:08:33.760>
    closer = 'gvanrossum'
    components = ['Interpreter Core']
    creation = <Date 2019-05-10.20:40:16.492>
    creator = 'msullivan'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36878
    keywords = ['patch']
    message_count = 9.0
    messages = ['342130', '342144', '342213', '343130', '343198', '343205', '343236', '343237', '343240']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'levkivskyi', 'miss-islington', 'msullivan']
    pr_nums = ['13238', '13479', '13504']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue36878'
    versions = ['Python 3.8']

    @msullivan
    Copy link
    Mannequin Author

    msullivan mannequin commented May 10, 2019

    Per discussion during the typing summit at PyCon, it would be a good idea to allow extra information to be included in # type: ignore comments, in order to allow behavior such as suppressing individual errors (for example, with syntax like # type: ignore[E1000], to suppress error 1000).

    My proposal, then, is to generalize the definition of type: ignore comments to be # type: ignore followed by a non-alphanumeric character. Then # type: ignore[E1000]and# type: ignore E1000would be valid type ignore comments while# type: ignoreE1000` would not be.

    Now that ast.parse can parse type_comments, this needs to make it into 3.8, basically, if we want to do this and be able to use the ast type_comment feature.

    Ideally, the text of the type ignore would be actually included in the produced AST. As a bare minimum first step, we need to recognize type ignores with extra information and report them (and, critically, not detect them as regular type comments and produce errors when they appear in unexpected places).

    I'll put up a PR to do the second part shortly.

    @msullivan msullivan mannequin added 3.8 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels May 10, 2019
    @ilevkivskyi
    Copy link
    Member

    I like the idea of separate smaller PRs, the first one looks good.

    @ilevkivskyi
    Copy link
    Member

    New changeset d8320ec by Ivan Levkivskyi (Michael J. Sullivan) in branch 'master':
    bpo-36878: Allow extra text after # type: ignore comments (GH-13238)
    d8320ec

    @gvanrossum
    Copy link
    Member

    How many more PRs do you plan? Or is this it?

    @ilevkivskyi
    Copy link
    Member

    New changeset 933e150 by Ivan Levkivskyi (Michael J. Sullivan) in branch 'master':
    bpo-36878: Track extra text added to 'type: ignore' in the AST (GH-13479)
    933e150

    @msullivan
    Copy link
    Mannequin Author

    msullivan mannequin commented May 22, 2019

    I think there will be one more PR to disallow non-ASCII characters immediately after a # type: ignore, but otherwise I think this is done

    @miss-islington
    Copy link
    Contributor

    New changeset d8a82e2 by Miss Islington (bot) (Michael J. Sullivan) in branch 'master':
    bpo-36878: Only allow text after # type: ignore if first character ASCII (GH-13504)
    d8a82e2

    @gvanrossum
    Copy link
    Member

    Thanks!

    @msullivan
    Copy link
    Mannequin Author

    msullivan mannequin commented May 22, 2019

    I think this is done!

    @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.8 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants