[Numpy-discussion] Casting Bug or a "Feature"?

Georg Brandl g.brandl@gmx....
Fri Jan 18 02:31:23 CST 2013

Am 17.01.2013 17:21, schrieb Chris Barker - NOAA Federal:
> On Wed, Jan 16, 2013 at 11:34 PM, Matthieu Brucher
>> Of course a += b is not the same as a = a + b. The first one modifies the
>> object a, the second one creates a new object and puts it inside a. The
>> behavior IS consistent.
> Exactly -- if you ask me, the bug is that Python allows "in_place"
> operators for immutable objects -- they should be more than syntactic
> sugar.

They are not -- the "+=" translation is well defined: the equivalents are

a += b
a = a.__iadd__(b)

Now __iadd__ can choose to return self (for mutable objects) or a new object
(for immutable objects).  The confusion about immutables is simply the
"usual" confusion about "=" assigning names, not variable space.

> Of course, the temptation for += on regular numbers was just too much to resist.

And probably 95% of the use of +=/-= *is* with regular numbers.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130118/04136005/attachment.bin 

More information about the NumPy-Discussion mailing list