Augmented Assignment (was: Re: PEP scepticism)

Thomas Wouters thomas at xs4all.net
Mon Jul 2 09:20:13 CEST 2001


On Sun, Jul 01, 2001 at 07:34:07PM -0700, Emile van Sebille wrote:

> > It would be quite legal for id(b) to be identical in one case - since b
> > is the only reference to the tuple, the original tuple could be
> > collected, and a new tuple with the same id() could be allocated. It's
> > unlikely, but possible.

> I'm not sure that's true.  It looks like the old (collectible) reference
> exists until the STORE_FAST is executed, and IIRC, individual byte code
> commands are atomic and execute until completion without interference.

> Do I have that right?

You do. The new tuple gets created before the old one is destroyed. Even if
my *first* attempt at augmented assignment (which used new two-argument
bytecodes to do inplace-operation-and-store in 1 bytecode) had been
accepted, it probably wouldn't have worked that way: you don't want to
destroy the old value until you are sure you can create the new value
without raising an exception.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list