[issue17973] FAQ entry for: '+=' on a list inside tuple both succeeds and raises an exception
Andy Chugunov added the comment: Thank you guys for all the efforts you put in solving and answering this. Just so that we're clear. It is perfectly legitimate to extend lists withing tuples. It just doesn't seem possible to make augmented assignment and simple assignment handle this particular operation correctly without unduly sacrificing their general efficiency. Use append() on the lists instead. Is that correct? -- ___ Python tracker <http://bugs.python.org/issue17973> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] '+=' on a list inside tuple both succeeds and raises an exception
New submission from Andy Chugunov: At the same time append() succeeds silently, while simple '+' fails. Here's an example: >>> a = ([1],) >>> a[0].append(2) >>> a ([1, 2],) >>> a[0] += [3] Traceback (most recent call last): File "", line 1, in a[0] += [3] TypeError: 'tuple' object does not support item assignment >>> a ([1, 2, 3],) >>> a[0] = a[0] + [4] Traceback (most recent call last): File "", line 1, in a[0] = a[0] + [4] TypeError: 'tuple' object does not support item assignment >>> a ([1, 2, 3],) >>> Looks like a self-contradictory behavior. Unfortunately, I'm not yet advanced enough to figure out where the problem might be and submit a fix. Tested with v3.3.1 on Windows 7 (64-bit), and v3.2.3 and v2.7.3 on Debian 7 (also 64-bit). -- messages: 189201 nosy: andy.chugunov priority: normal severity: normal status: open title: '+=' on a list inside tuple both succeeds and raises an exception type: behavior versions: Python 2.7, Python 3.3 ___ Python tracker <http://bugs.python.org/issue17973> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] '+=' on a list inside tuple both succeeds and raises an exception
Andy Chugunov added the comment: Thank you for the clarification! The exception is appropriate as tuples have to stay immutable. Got it. Could you please also explain a bit about the append() call? Should it in theory raise an exception as well or is such clean behavior intended? -- ___ Python tracker <http://bugs.python.org/issue17973> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com