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: can you add this new feature about grammar?
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.9
process
Status: closed Resolution: postponed
Dependencies: Superseder:
Assigned To: Nosy List: aeros, dai dai, steven.daprano, xtreak
Priority: normal Keywords:

Created on 2019-07-13 06:50 by dai dai, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (6)
msg347779 - (view) Author: dai dai (dai dai) Date: 2019-07-13 06:50
>> a = 1
>> b = 2
>> a, b += 1, 2
2  3
msg347780 - (view) Author: dai dai (dai dai) Date: 2019-07-13 06:51
>> a = 1
>> b = 2
>> a, b += 1, 2
2, 4
msg347781 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-07-13 07:17
Changes like this needs to be discussed in python-ideas first https://mail.python.org/mailman3/lists/python-ideas.python.org/ . The current behavior is as below : 

>>> a, b += 1, 2
  File "<stdin>", line 1
SyntaxError: illegal expression for augmented assignment

See also for some reference to the initial PEP proposal : https://stackoverflow.com/a/18132749/2610955

There is also a comment related to this where this error is raised https://github.com/python/cpython/blob/b9a0376b0dedf16a2f82fa43d851119d1f7a2707/Python/ast.c#L3302

Augmented assignments can only have a name, a subscript, or an
attribute on the left, though, so we have to explicitly check for
those.

I would propose closing this now and reopening this if there is some consensus on moving forward with this in python-ideas.
msg347782 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-07-13 07:23
A new language feature like this needs to be discussed on Python-Ideas first, to get community feedback, to decide whether the feature is desired by the community, to iron-out any bugs in the specification, and decide whether or not you will need to write a PEP first. (You probably will.)

https://mail.python.org/mailman3/lists/python-ideas.python.org/

https://www.python.org/dev/peps/

Until then, I'm closing this as Postponed.
msg347783 - (view) Author: Kyle Stanley (aeros) * (Python committer) Date: 2019-07-13 07:24
Thanks for the suggestion.

Personally I wouldn't be in favor of this particular change. It doesn't add any additional functionality beyond saving a couple of characters. Also, this could quickly get rather convoluted. For separation and clarity, the assignment operators ("+=", "-=", "/=", "*=", etc) should affect one variable. If you wanted to fit multiple on the same line, you could simply use:

>>> a += 1; b += 2
msg347784 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-07-13 07:28
Oops, I accidentally removed xtreak, and then aeros167 accidentally removed me.
History
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81763
2019-07-13 07:28:59steven.dapranosetnosy: + steven.daprano, xtreak
type: enhancement
messages: + msg347784
2019-07-13 07:24:42aerossetnosy: + aeros, - steven.daprano
type: enhancement -> (no value)
messages: + msg347783
2019-07-13 07:23:01steven.dapranosetstatus: open -> closed

type: enhancement
components: + Interpreter Core
versions: + Python 3.9
nosy: + steven.daprano, - xtreak
messages: + msg347782
resolution: postponed
stage: resolved
2019-07-13 07:17:09xtreaksetnosy: + xtreak
messages: + msg347781
2019-07-13 06:51:49dai daisetmessages: + msg347780
2019-07-13 06:50:47dai daicreate