Is this a bug?

Grant Edwards grante at visi.com
Sun Apr 24 22:03:27 EDT 2005


On 2005-04-25, Terry Reedy <tjreedy at udel.edu> wrote:
>>    According to the language reference,
>>
>>      An augmented assignment expression like x += 1 can be
>>      rewritten as x = x + 1 to achieve a similar, but not
>>      exactly equal effect. In the augmented version, x is only
>>      evaluated once.
>>
>>    I don't consider the two results you posted "similar".
>
> It continues
> "Also, when possible, the actual operation is performed in-place, meaning 
> that rather than creating a new object and assigning that to the target, 
> the old object is modified instead. ...Similarly, with the exception of the 
> possible in-place behavior, the binary operation performed by augmented 
> assignment is the same as the normal binary operations.
> "
> I take the behavior observed to be the exceptional in-place behavior 
> referred to.

I certainly don't see how.  Strings are immutable.  The old
object can't be modified in-place, so the "in-place" behavior
is moot.

In any case, the only difference is supposed to be whether a
new object is created or an existing object is modified.  The
two results shouldn't be completely different as shown by the
OP.  

Your quote states quite clearly that the binary operation *is
the same* whether it's spelt a = a + b or a += b.  That is
simply not true for the example we're discussing.

> But this could certainly be clearer.

I don't see how that statement has anything to do with the bug
at hand.

-- 
Grant Edwards                   grante             Yow!  Oh my GOD -- the
                                  at               SUN just fell into YANKEE
                               visi.com            STADIUM!!



More information about the Python-list mailing list