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 daniel.urban
Recipients daniel.urban, santoso.wijaya, scgtrp, slav0nic, stutzbach
Date 2011-03-16.12:15:45
SpamBayes Score 0.018377166
Marked as misclassified No
Message-id <1300277746.36.0.271295159379.issue11562@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2011-03-16 12:15:46daniel.urbansetrecipients: + daniel.urban, stutzbach, santoso.wijaya, scgtrp, slav0nic
2011-03-16 12:15:46daniel.urbansetmessageid: <1300277746.36.0.271295159379.issue11562@psf.upfronthosting.co.za>
2011-03-16 12:15:45daniel.urbanlinkissue11562 messages
2011-03-16 12:15:45daniel.urbancreate