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

compile() error on AST object with assignment expression #80513

Closed
tomyun mannequin opened this issue Mar 17, 2019 · 4 comments
Closed

compile() error on AST object with assignment expression #80513

tomyun mannequin opened this issue Mar 17, 2019 · 4 comments
Labels
3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@tomyun
Copy link
Mannequin

tomyun mannequin commented Mar 17, 2019

BPO 36332
Nosy @gvanrossum, @serhiy-storchaka, @emilyemorehouse, @pablogsal, @tomyun
PRs
  • bpo-36332: Allow compile() to handle AST objects with assignment expressions #12398
  • 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-03-18.13:52:11.747>
    created_at = <Date 2019-03-17.22:10:50.820>
    labels = ['interpreter-core', 'type-bug', '3.8']
    title = 'compile() error on AST object with assignment expression'
    updated_at = <Date 2019-03-18.13:52:11.747>
    user = 'https://github.com/tomyun'

    bugs.python.org fields:

    activity = <Date 2019-03-18.13:52:11.747>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-03-18.13:52:11.747>
    closer = 'pablogsal'
    components = ['Interpreter Core']
    creation = <Date 2019-03-17.22:10:50.820>
    creator = 'tomyun'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36332
    keywords = ['patch']
    message_count = 4.0
    messages = ['338143', '338161', '338163', '338223']
    nosy_count = 5.0
    nosy_names = ['gvanrossum', 'serhiy.storchaka', 'emilyemorehouse', 'pablogsal', 'tomyun']
    pr_nums = ['12398']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36332'
    versions = ['Python 3.8']

    @tomyun
    Copy link
    Mannequin Author

    tomyun mannequin commented Mar 17, 2019

    Seems like compile() can't properly handle assignment expressions parsed in AST object.

    Python 3.8.0a2+ (heads/master:06e1e68, Mar 17 2019, 14:27:19)
    [Clang 10.0.0 (clang-1000.10.44.4)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import ast
    >>> compile("if a == 1:\n  True", '<string>', 'exec')
    <code object <module> at 0x10a59ef60, file "<string>", line 1>
    >>> compile(ast.parse("if a == 1:\n  True"), '<string>', 'exec')
    <code object <module> at 0x10a5f6780, file "<string>", line 1>
    >>> compile("if a := 1:\n  True", '<string>', 'exec')
    <code object <module> at 0x10a59ef60, file "<string>", line 1>
    >>> compile(ast.parse("if a := 1:\n  True"), '<string>', 'exec')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    SystemError: unexpected expression
    >>>

    This issue seems to break IPython when trying to use any assignment expressions.
    ipython/ipython#11618

    @tomyun tomyun mannequin added 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Mar 17, 2019
    @gvanrossum
    Copy link
    Member

    Confirmed. Emily, do you need help tracking this down?

    @serhiy-storchaka
    Copy link
    Member

    validate_expr() needs a case for NamedExpr_kind.

    I think also that it is better to remove the "default" clause (and move its code after the switch statement) and allow the compiler to warn about missed cases.

    @pablogsal
    Copy link
    Member

    New changeset 0c9258a by Pablo Galindo in branch 'master':
    bpo-36332: Allow compile() to handle AST objects with assignment expressions (GH-12398)
    0c9258a

    @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 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants