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: syntax: no unpacking in augassign
Type: Stage:
Components: Documentation Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, jura05, terry.reedy, vstinner
Priority: normal Keywords:

Created on 2009-01-06 13:11 by jura05, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg79256 - (view) Author: jura (jura05) Date: 2009-01-06 13:11
the following code produces syntax error:
>>> (x, y) += 1
While this is documented in
http://docs.python.org/3.0/reference/simple_stmts.html#augmented-assignment-statements
("An augmented assignment evaluates the target (which, unlike normal
аssignment statements, cannot be an unpacking)..."),
the syntax specification doesn't reflect this:
http://docs.python.org/3.0/reference/simple_stmts.html#grammar-token-augmented_assignment_stmt
http://docs.python.org/3.0/reference/grammar.html
msg79258 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-01-06 13:18
Extract of the grammar:
  target          ::=  identifier | ...
  target_list     ::=  target ("," target)* [","]
  assignment_stmt ::=  (target_list "=")+ ...
  augmented_assignment_stmt ::=  target augop ...
  augop                     ::=  "+=" | ...

So there is only one possible target for "... += ..." and multiple 
targets for "... = ..".
msg79260 - (view) Author: jura (jura05) Date: 2009-01-06 13:23
Yes, but
target ::= identifier | "(" target_list ")" | ...
so (x,y) seems to be a valid target.
msg79262 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-01-06 13:33
Oh yes! I didn't see "(" target_list ")" | "[" target_list "]", sorry.
msg79515 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-01-09 21:55
The grammar in the doc is not the one used to generate the
parser/compiler.  The former is meant to be easier for humans to read,
the latter easier for the parser generator.  Neither completely embody
Python's syntax rules.  Additional restrictions may be applied later in
the chain.  From:
http://svn.python.org/view/python/trunk/Grammar/Grammar?rev=65872&view=auto

expr_stmt: testlist (augassign (yield_expr|testlist) |
                     ('=' (yield_expr|testlist))*)

augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |
            '<<=' | '>>=' | '**=' | '//=')
# For normal assignments, additional restrictions enforced by the
interpreter

Perhaps that should say "For augmented assignments....

Except maybe for the comment above, I think this issue can be closed.
msg80099 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-01-18 13:47
Fixed in r68725.
History
Date User Action Args
2022-04-11 14:56:43adminsetgithub: 49107
2009-01-18 13:47:52georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg80099
2009-01-09 21:55:38terry.reedysetnosy: + terry.reedy
messages: + msg79515
2009-01-06 13:33:24vstinnersetmessages: + msg79262
2009-01-06 13:23:38jura05setmessages: + msg79260
2009-01-06 13:18:48vstinnersetnosy: + vstinner
messages: + msg79258
2009-01-06 13:11:53jura05create