Aaron Brady wrote:

>>>> f.func_defaults[0]
> [2, 3]
>>>> f.func_defaults[0]+=[4]
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: 'tuple' object does not support item assignment
>>>> f.func_defaults[0]
> [2, 3, 4]
> 
> V. interesting.  Operation succeeds but with a throw.  Er, raise.

This is not specific to func_defaults:

>>> t = ([1],)
>>> t[0] += [2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> t
([1, 2],)

t[0] += [2]

is resolved to

t.__setitem__(t[0].__iadd__([2]))

where list.__iadd__() succeeds but __setitem__() fails (because tuples don't
have that method).

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to