Daniel Urban <urban.dani...@gmail.com> added the comment:

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

----------
nosy: +durban

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11562>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to