Why not a, b += i, j? (augmented assignment via tuple unpacking)

Jeff Epler jepler at unpythonic.net
Wed Nov 27 10:39:57 EST 2002


On Wed, Nov 27, 2002 at 05:49:59PM +1300, Greg Ewing wrote:
> Jeff Epler wrote:
> 
> >but in that case, what is
> >    a, b += t
> >equivalent to?
> 
> 
> Obviously it's
> 
>    a, b = iadd(a, t[0]), iadd(a, t[1])
> 
> >What about
> >    t += a, b
> 
> 
> This is already meaningful:
> 
>    t = iadd(t, (a, b))

Right now
    t = i, j
    a, b = t
    del t
is equivalent to
    a, b = i, j
except that the temporary t is never created (it resides on the stack)

But that means that you'd want
    t = a, b
    t += i, j
    a, b = t
    del t
to be equivalent to
    a, b += i, j
but now 't += (i, j)' has been given two different meanings -- the one
it has already, and the one it would need to have to make "augmented
assignment via tuple unpacking" work in the "desired" way.

Jeff




More information about the Python-list mailing list