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

josef.pktd at gmail.com josef.pktd at gmail.com
Thu Jan 17 07:27:44 EST 2013


On Thu, Jan 17, 2013 at 2:34 AM, Matthieu Brucher
<matthieu.brucher at gmail.com> wrote:
> Hi,
>
> Actually, this behavior is already present in other languages, so I'm -1 on
> additional verbosity.
> 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.

The inplace operation is standard, but my guess is that the silent
downcasting is not.

in python

>>> a = 1
>>> a += 5.3
>>> a
6.2999999999999998
>>> a = 1
>>> a *= 1j
>>> a
1j

I have no idea about other languages.

Josef

>
> Cheers,
>
> Matthieu
>
>
> 2013/1/17 Paul Anton Letnes <paul.anton.letnes at gmail.com>
>>
>> On 17.01.2013 04:43, Patrick Marsh wrote:
>> > Thanks, everyone for chiming in.  Now that I know this behavior
>> > exists, I can explicitly prevent it in my code. However, it would be
>> > nice if a warning or something was generated to alert users about the
>> > inconsistency between var += ... and var = var + ...
>> >
>> >
>> > Patrick
>> >
>>
>> I agree wholeheartedly. I actually, for a long time, used to believe
>> that python would translate
>> a += b
>> to
>> a = a + b
>> and was bitten several times by this bug. A warning (which can be
>> silenced if you desperately want to) would be really nice, imho.
>>
>> Keep up the good work,
>> Paul
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
>
> --
> Information System Engineer, Ph.D.
> Blog: http://matt.eifelle.com
> LinkedIn: http://www.linkedin.com/in/matthieubrucher
> Music band: http://liliejay.com/
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list