[New-bugs-announce] [issue39988] Remove AugLoad and AugStore expression context from AST

Serhiy Storchaka report at bugs.python.org
Tue Mar 17 03:29:51 EDT 2020


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

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.

----------
components: Interpreter Core
messages: 364390
nosy: BTaskaya, benjamin.peterson, brett.cannon, pablogsal, serhiy.storchaka, yselivanov
priority: normal
severity: normal
status: open
title: Remove AugLoad and AugStore expression context from AST
type: enhancement
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39988>
_______________________________________


More information about the New-bugs-announce mailing list