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 AST validation for Constant nodes #84181

Closed
isidentical opened this issue Mar 18, 2020 · 6 comments
Closed

Improve AST validation for Constant nodes #84181

isidentical opened this issue Mar 18, 2020 · 6 comments
Assignees
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@isidentical
Copy link
Sponsor Member

BPO 40000
Nosy @vstinner, @serhiy-storchaka, @pablogsal, @isidentical
PRs
  • bpo-40000: Improve AST validation for invalid constant nodes #19055
  • 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/isidentical'
    closed_at = <Date 2020-03-19.12:01:11.736>
    created_at = <Date 2020-03-18.09:46:11.962>
    labels = ['type-feature', 'library', '3.9']
    title = 'Improve AST validation for Constant nodes'
    updated_at = <Date 2020-03-19.18:43:55.107>
    user = 'https://github.com/isidentical'

    bugs.python.org fields:

    activity = <Date 2020-03-19.18:43:55.107>
    actor = 'vstinner'
    assignee = 'BTaskaya'
    closed = True
    closed_date = <Date 2020-03-19.12:01:11.736>
    closer = 'BTaskaya'
    components = ['Library (Lib)']
    creation = <Date 2020-03-18.09:46:11.962>
    creator = 'BTaskaya'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40000
    keywords = ['patch']
    message_count = 6.0
    messages = ['364505', '364509', '364529', '364530', '364599', '364626']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'serhiy.storchaka', 'pablogsal', 'BTaskaya']
    pr_nums = ['19055']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue40000'
    versions = ['Python 3.9']

    @isidentical
    Copy link
    Sponsor Member Author

    When something that isn't constant found in a ast.Constant node's body, python reports errors like this

    >>> e = ast.Expression(body=ast.Constant(value=type))
    >>> ast.fix_missing_locations(e)
    <_ast.Expression object at 0x7fc2c23981c0>
    >>> compile(e, "<test>", "eval")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: got an invalid type in Constant: type

    But if something is part of constant tuple and frozenset isn't constant, the error reporting is wrong

    >>> e = ast.Expression(body=ast.Constant(value=(1,2,type)))
    >>> compile(e, "<test>", "eval")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: got an invalid type in Constant: tuple

    This should've been

    TypeError: got an invalid type in Constant: type

    @isidentical isidentical added stdlib Python modules in the Lib dir 3.9 only security fixes labels Mar 18, 2020
    @isidentical isidentical self-assigned this Mar 18, 2020
    @isidentical isidentical added type-feature A feature request or enhancement stdlib Python modules in the Lib dir 3.9 only security fixes labels Mar 18, 2020
    @isidentical isidentical self-assigned this Mar 18, 2020
    @isidentical isidentical added the type-feature A feature request or enhancement label Mar 18, 2020
    @serhiy-storchaka
    Copy link
    Member

    You got an anniversary issue!

    @vstinner
    Copy link
    Member

    Congratulations Batuhan! You win with the bug number 40000! A nice number ;-) To be honest, I wanted to get it, but I didn't want to cheat by opening a stupid issue.

    @isidentical
    Copy link
    Sponsor Member Author

    sorry to take it Victor, maybe you can get the perfect issue number when we migrate to github?

    @pablogsal
    Copy link
    Member

    New changeset 0ac59f9 by Batuhan Taşkaya in branch 'master':
    bpo-40000: Improve error messages when validating invalid ast.Constant nodes (GH-19055)
    0ac59f9

    @vstinner
    Copy link
    Member

    _PyType_Name(Py_TYPE(value)))

    Why truncating the type name in the error message? The qualified name (don't call _PyType_Name()) should provide more information, no?

    @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.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants