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

Jeff Epler jepler at unpythonic.net
Mon Jun 3 14:24:41 EDT 2002


Maybe the bytecode for inplace operations like
    f[i] += v
should implement the
pseudocode
    _temp = f[i] 
    _new = inplace_add(_temp, v)
    if _new is not _temp:
	f[i] = _new
    del _temp, _new

Then, the following would work:
    >>> x = ([1], [2])
    >>> x[0] += [3]
    >>> x
    ([1, 3], [2])
and the following would continue to not work
    >>> x = (1, 2)
    >>> x[0] += 3
    TypeError: object doesn't support item assignment

However, this would probably double the bytecode size of the sequence,
and hurt performance similarly....

And personally, I still never use augmented-assignment syntax anyway..

Jeff





More information about the Python-list mailing list