[New-bugs-announce] [issue17973] '+=' on a list inside tuple both succeeds and raises an exception

Andy Chugunov report at bugs.python.org
Tue May 14 10:19:37 CEST 2013


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 "<pyshell#47>", line 1, in <module>
    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 "<pyshell#49>", line 1, in <module>
    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 <report at bugs.python.org>
<http://bugs.python.org/issue17973>
_______________________________________


More information about the New-bugs-announce mailing list