This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Remove AugLoad and AugStore expression context from AST
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, benjamin.peterson, brett.cannon, oconnor663, pablogsal, sanjeev091, serhiy.storchaka, yselivanov
Priority: normal Keywords: patch

Created on 2020-03-17 07:29 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19038 merged serhiy.storchaka, 2020-03-17 07:38
Messages (5)
msg364390 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-03-17 07:29
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 issue39987. See also similar issue39969.
msg364422 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-03-17 12:47
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.
msg364480 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-03-17 21:41
New changeset 6b97598fb66a08d0f36e4d73bffea5c1b17740d4 by Serhiy Storchaka in branch 'master':
bpo-39988: Remove ast.AugLoad and ast.AugStore node classes. (GH-19038)
https://github.com/python/cpython/commit/6b97598fb66a08d0f36e4d73bffea5c1b17740d4
msg364713 - (view) Author: Jack O'Connor (oconnor663) * Date: 2020-03-20 20:12
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
msg364714 - (view) Author: Jack O'Connor (oconnor663) * Date: 2020-03-20 20:13
Ah never mind, it looks like that's covered by https://bugs.python.org/issue39999
History
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84169
2020-03-20 20:13:32oconnor663setmessages: + msg364714
2020-03-20 20:12:24oconnor663setnosy: + oconnor663
messages: + msg364713
2020-03-17 21:50:06serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-03-17 21:41:16serhiy.storchakasetmessages: + msg364480
2020-03-17 16:25:48ned.deilysetmessages: - msg364424
2020-03-17 12:54:31sanjeev091setnosy: + sanjeev091
messages: + msg364424
2020-03-17 12:47:03serhiy.storchakasetmessages: + msg364422
2020-03-17 07:38:45serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request18389
2020-03-17 07:29:51serhiy.storchakacreate