This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author oscarbenjamin
Recipients Ramchandra Apte, Sergey, aleax, ethan.furman, jcea, oscarbenjamin, serhiy.storchaka, terry.reedy
Date 2013-07-11.14:39:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1373553563.92.0.903845847464.issue18305@psf.upfronthosting.co.za>
In-reply-to
Content
This "optimisation" is a semantic change. It breaks backward compatibility in cases where a = a + b and a += b do not result in the name a having the same value. In particular this breaks backward compatibility for numpy users.

Numpy arrays treat += differently from + in the sense that a += b coerces b to the same dtype as a and then adds in place whereas a + b uses Python style type promotion. This behaviour is by design and it is useful. It is also entirely appropriate (unlike e.g. summing lists) that someone would use sum() to add numpy arrays.

An example where + and += give different results:

>>> from numpy import array
>>> a1 = array([1, 2, 3], dtype=int)
>>> a1
array([1, 2, 3])
>>> a2 = array([.5, .5, .5], dtype=float)
>>> a2
array([ 0.5,  0.5,  0.5])
>>> a1 + a2
array([ 1.5,  2.5,  3.5])
>>> a1 += a2
>>> a1
array([1, 2, 3])
History
Date User Action Args
2013-07-11 14:39:24oscarbenjaminsetrecipients: + oscarbenjamin, aleax, terry.reedy, jcea, ethan.furman, Ramchandra Apte, serhiy.storchaka, Sergey
2013-07-11 14:39:23oscarbenjaminsetmessageid: <1373553563.92.0.903845847464.issue18305@psf.upfronthosting.co.za>
2013-07-11 14:39:23oscarbenjaminlinkissue18305 messages
2013-07-11 14:39:23oscarbenjamincreate