TypeError expected in an augmented assignment

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Jul 3 14:43:23 CEST 2014


On 03/07/2014 10:35, candide wrote:
>
>
>> >From that link:
>>
>>
>>
>> """
>>
>> An augmented assignment expression like x += 1 can be rewritten as x =
>>
>> x + 1 to achieve a similar, but not exactly equal effect. In the
>>
>> augmented version, x is only evaluated once. Also, when possible, the
>>
>> actual operation is performed in-place, meaning that rather than
>>
>> creating a new object and assigning that to the target, the old object
>>
>> is modified instead.
>>
>> """
>>
>>
>>
>> The significance here is that the augmented assignment may not
>>
>> necessarily be at all comparable to the non-augmented version, but
>>
>> ought to have *approximately* the same *intention*.
>
>
> This is not my reading.
>
>
>
>
>>
>> of situations where the two will differ, eg when there are multiple
>>
>> references to the same object:
>>
>>
>>
>>>>> a = b = [1,2]
>>
>>>>> a += [3]
>>
>>>>> a,b
>>
>> ([1, 2, 3], [1, 2, 3])
>>
>>>>> a = a + [4]
>>
>>>>> a,b
>>
>> ([1, 2, 3, 4], [1, 2, 3])
>>
>>
>
> OK but this behavior is in conformance with the Reference Manual (cf. your quote above : "when possible, the actual operation is performed in-place"). This is not my point because the doc explictly claims that "an augmented assignment [...] performs the binary operation specific to the type of assignment on the two operands".
>

To get the wording changed to satisfy yourself, either raise an issue on 
the bug tracker at bugs.python.org and attach a patch file, or send an 
email with suggested wording to docs at python.org.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com





More information about the Python-list mailing list