[Python-Dev] Compilation of "except FooExc as var" adds useless store
06.01.19 13:10, Paul Sokolovsky ????:
> Storing None looks superfluous. For example, DELETE_FAST explicitly
> stores NULL on delete.
> Likewise, for DELETE_NAME/DELETE_GLOBAL, PyObject_DelItem() is
> called which translates to:
> m->mp_ass_subscript(o, key, (PyObject*)NULL);
> So hopefully any compliant mapping implementation actually clears
> stored value, not leaving it dangling.
> The "store None" behavior can be traced down to introduction of the
> "del except target var" behavior back in 2007:
> There's no clear explanation why it's done like that, so probably an
> artifact of the initial implementation. Note that even
> which did quite a bunch of refactoring to "except" implementation, and
> reformatted this code, otherwise left it in place.
Because there is a reason for such code.
See issue1631942  and the thread with the subject "self-contained
exceptions" on the Python-3000 mailing list  for the rationale.
In short, the code
except Exception as e:
I do not see a problem with storing None before deleting a variable.
This is not a performance critical code, because it is executed only
when an exception was raised and caught.