On Wed, Apr 24, 2013 at 6:58 PM, Oscar Benjamin
<oscar.j.benja...@gmail.com> wrote:
> And here's another example:
>>>> c = ([],)
>>>> c
> ([],)
>>>> c[0] = c[0] + [1]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: 'tuple' object does not support item assignment
>>>> c
> ([],)
>>>> c[0] += [1]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: 'tuple' object does not support item assignment
>>>> c
> ([1],)

The interpreter always uses a STORE operation after an in-place
operation because it doesn't know if the target object was mutated
in-place -- not with how it's currently implemented in ceval.c (in
principle it could). This leads to half-completed operations that
raise a TypeError like this when it tries to store the mutated object
back to an immutable container. This can happen with any object that
doesn't support assigning to subscripts or attributes, not just a
tuple.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to