3 ms·
Why couldn't Python do something like: >>> _tmp = getitem(t, 0) >>> setitem(t, 0, _tmp) >>> try: >>> _tmp2 = _tmp.__iadd__([2]) >>> exc
by aftbit 12y ago
Why couldn't Python do something like:
>>> _tmp = getitem(t, 0)
>>> setitem(t, 0, _tmp)
>>> try:
>>> _tmp2 = _tmp.__iadd__([2])
>>> except AttributeError:
>>> _tmp2 = _tmp.__add__([2])
>>> setitem(t, 0, _tmp2)
Then if the first setitem raises, the rest of the code will be skipped. Obviously this isn't perfect:
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.
But otherwise, it seems like a pretty straightforward improvement, no?