Augmented Assignment (was: Re: PEP scepticism)
Thomas Wouters
thomas at xs4all.net
Mon Jul 2 03:17:35 EDT 2001
On Mon, Jul 02, 2001 at 02:00:51AM +0000, Rainer Deyke wrote:
> "Delaney, Timothy" <tdelaney at avaya.com> wrote in message
> news:mailman.994035602.29848.python-list at python.org...
> An interesting (and AFAIK legal) optimization would be to make tuples act as
> mutable objects with respect to augmented assignment if their reference is
> 1.
But they are never 1 unless you're in a C extention that just created it.
When you call 'x += y', the refcount for both x and y is always 2 when the
arguments arrive at the __iadd__ (or C equivalent.)
So you mean '2'. But then you could run into trouble on, say,
() += y
because the empty tuple is shared, just like interned strings and integers.
The refcount *could* be 2, and you end up modifying someone else's empty
tuple.
--
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