Why couldn't Python do something like:<p><pre><code> >>> _tmp = getitem(t, 0)
>>> setitem(t, 0, _tmp)
>>> try:
>>> _tmp2 = _tmp.__iadd__([2])
>>> except AttributeError:
>>> _tmp2 = _tmp.__add__([2])
>>> setitem(t, 0, _tmp2)
</code></pre>
Then if the first setitem raises, the rest of the code will be skipped. Obviously this isn't perfect:<p>1. If setitem has strange side-effects, this will cause them to happen twice.
2. If setitem raises based on the value (rather than the key), this won't notice that.<p>But otherwise, it seems like a pretty straightforward improvement, no?