Message131105
The reason of this behaviour is that x += 1 basically is the same as x = x.__iadd__(1). In the tuple case: t[1] = t[1].__iadd__([6]). The __iadd__ call mutates the list, then the tuple item assignment raises the TypeError.
See these examples:
>>> import dis
>>> dis.dis('x += 1')
1 0 LOAD_NAME 0 (x)
3 LOAD_CONST 0 (1)
6 INPLACE_ADD
7 STORE_NAME 0 (x)
10 LOAD_CONST 1 (None)
13 RETURN_VALUE
>>>
>>> dis.dis('t[1] += [6]')
1 0 LOAD_NAME 0 (t)
3 LOAD_CONST 0 (1)
6 DUP_TOP_TWO
7 BINARY_SUBSCR
8 LOAD_CONST 1 (6)
11 BUILD_LIST 1
14 INPLACE_ADD
15 ROT_THREE
16 STORE_SUBSCR
17 LOAD_CONST 2 (None)
20 RETURN_VALUE |
|
Date |
User |
Action |
Args |
2011-03-16 12:15:46 | daniel.urban | set | recipients:
+ daniel.urban, stutzbach, santoso.wijaya, scgtrp, slav0nic |
2011-03-16 12:15:46 | daniel.urban | set | messageid: <1300277746.36.0.271295159379.issue11562@psf.upfronthosting.co.za> |
2011-03-16 12:15:45 | daniel.urban | link | issue11562 messages |
2011-03-16 12:15:45 | daniel.urban | create | |
|