[Python-bugs-list] [ python-Bugs-668302 ] a = b += c, a += b = c gives syntax error

SourceForge.net noreply@sourceforge.net
Wed, 15 Jan 2003 08:20:00 -0800


Bugs item #668302, was opened at 2003-01-14 20:45
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=668302&group_id=5470

Category: Parser/Compiler
Group: Python 2.2.1
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: L. Peter Deutsch (lpd)
Assigned to: Nobody/Anonymous (nobody)
Summary: a = b += c, a += b = c gives syntax error

Initial Comment:
The new augmented assignment operators apparently are
not syntactically parallel to the assignment operator.
I can't come up with an immediate reason why they
shouldn't be, and I would like them to be.

Python 2.2.1, Red Hat Linux 7.3

I looked in the release notes for Python 2.2.2, and
didn't see anything about this. I also searched the
open bug list for "assignment", and didn't see this
mentioned.


----------------------------------------------------------------------

>Comment By: L. Peter Deutsch (lpd)
Date: 2003-01-15 08:20

Message:
Logged In: YES 
user_id=8861

I went back and read the language doc more carefully. I
didn't realize that a = b = c is handled differently from C,
Java, etc. in that after evaluating c, the assignments are
done from left to right -- i.e., there isn't even a
conceptual claim that this is like a = (b = c). So
assignments in Python are even less like expressions than I
had thought.

Nevertheless, I find it really irksome that I can write
        a[big_compllicated_expression] += 1
but I can't write
        x = a[big_complicated_expression] += 1
and instead have to write
        a[big_complicated_expression] = x =
a[big_complicated_expression] + 1
or
        a[big_complicated_expression] += 1
        x = a[big_complicated_expression]
or
        i = big_complicated_expression
        a[i] += 1
        x = a[i]
or
        i = big_complicated_expression
        a[i] = x = a[i] + 1

My suggestion was based on the belief that Python does
multiple assignments like a = b = c right to left. Since it
doesn't, I don't like the answer to "what would I like a = b
+= c to do". Nevertheless, I will answer the question. I
would like a = b += c to be exactly equivalent to
        b += c
        a = b
except that the targets are only evaluated once.

I realize that this amounts to right-to-left assignment
order, and since this is not consistent with the existing
Python order for multiple assignments, I'm willing to
withdraw the request -- for this reason, and this reason only.

Frankly, having understood the situation better, I think
augmented assignment is kind of warty.


----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2003-01-15 03:39

Message:
Logged In: YES 
user_id=6656

What would you have

a = b += c

do?

This has been discussed *somewhere* -- python-list, maybe?

I'm strongly against changing this, fwiw.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=668302&group_id=5470