Behavior of += (was Re: [Python-Dev] Customization docs)

jepler at unpythonic.net jepler at unpythonic.net
Sat Jun 1 10:03:16 EDT 2002


On Sat, Jun 01, 2002 at 09:32:39AM -0400, David Abrahams wrote:
> My question was about what a new type needs to do in order for things to
> work properly in Python. If, as I had incorrectly assumed, Python were
> checking a type's mutability before deciding whether it would be putting
> the result back into the sequence, I would need to know what criteria
> Python uses to decide mutability.

IMO the following is an odder behavior:
>>> t
([1], [2], [3])
>>> t[1] += [3]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: object doesn't support item assignment
>>> t
([1], [2, 3], [3])

Jeff





More information about the Python-list mailing list