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

Remove AugLoad and AugStore expression context from AST #84169

Closed
serhiy-storchaka opened this issue Mar 17, 2020 · 5 comments
Closed

Remove AugLoad and AugStore expression context from AST #84169

serhiy-storchaka opened this issue Mar 17, 2020 · 5 comments
Labels
3.9 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 39988
Nosy @brettcannon, @benjaminp, @serhiy-storchaka, @1st1, @oconnor663, @pablogsal, @isidentical, @sanjeev singh
PRs
  • bpo-39988: Remove ast.AugLoad and ast.AugStore node classes. #19038
  • 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 2020-03-17.21:50:06.088>
    created_at = <Date 2020-03-17.07:29:51.210>
    labels = ['interpreter-core', 'type-feature', '3.9']
    title = 'Remove AugLoad and AugStore expression context from AST'
    updated_at = <Date 2020-03-20.20:13:32.791>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2020-03-20.20:13:32.791>
    actor = 'oconnor663'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-03-17.21:50:06.088>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2020-03-17.07:29:51.210>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39988
    keywords = ['patch']
    message_count = 5.0
    messages = ['364390', '364422', '364480', '364713', '364714']
    nosy_count = 8.0
    nosy_names = ['brett.cannon', 'benjamin.peterson', 'serhiy.storchaka', 'yselivanov', 'oconnor663', 'pablogsal', 'BTaskaya', 'sanjeev091']
    pr_nums = ['19038']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue39988'
    versions = ['Python 3.9']

    @serhiy-storchaka
    Copy link
    Member Author

    AugLoad and AugStore are never exposed to the user. They are not generated by the parser and the compiler does not accept it.

    >>> from ast import *
    >>> tree = Module(body=[AugAssign(target=Name(id='x', ctx=AugStore()), op=Add(), value=Constant(value=1))], type_ignores=[])
    >>> compile(fix_missing_locations(tree), 'sample', 'exec')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: expression must have Store context but has AugStore instead

    They are only used in temporary nodes created by the compiler. But the support of AugLoad and AugStore is spread across many sites in the compiler, adding special cases which have very little in common with the "normal" cases of Load, Store and Del.

    The proposed PR removes AugLoad and AugStore. It moves support of the augmented assignment into a separate function and cleans up the rest of the code. This saves around 70 lines of handwritten code and around 60 lines of generated code.

    The PR depends on bpo-39987. See also similar bpo-39969.

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

    It is possible also to get rid of the ctx argument at all. The context may be determined by the parent nodes. But it is larger and breaking change, so I'll open a separate issue for it.

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 6b97598 by Serhiy Storchaka in branch 'master':
    bpo-39988: Remove ast.AugLoad and ast.AugStore node classes. (GH-19038)
    6b97598

    @oconnor663
    Copy link
    Mannequin

    oconnor663 mannequin commented Mar 20, 2020

    This change may have broken pyflakes on nightly Python. Is that expected or problematic?

    Error message:

    "pyflakes" failed during execution due to "module 'ast' has no attribute 'AugLoad'"
    

    Seen at: https://travis-ci.org/github/buildinspace/peru/jobs/665005023

    @oconnor663
    Copy link
    Mannequin

    oconnor663 mannequin commented Mar 20, 2020

    Ah never mind, it looks like that's covered by https://bugs.python.org/issue39999

    @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 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