[Python-Dev] Compilation of "except FooExc as var" adds useless store
pmiscml at gmail.com
Sun Jan 6 13:48:39 EST 2019
On Sun, 6 Jan 2019 17:26:09 +0200
Serhiy Storchaka <storchaka at gmail.com> wrote:
> 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:
> del e
> should work.
(Dark) Magic. Live and learn/think. So, we allow user to delete a var,
then recreate it, just to delete again. Thanks for both the hint and
I can only agree with what Chris wrote in the initial reply - it
would nice if there would be an explanation of these tricks somewhere.
I myself wouldn't know a better place than the source code comments.
Well, at least I did trace it to the source code where it's handled.
> 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.
From CPython's points of view, I might (well, have to) agree. But I was
pretty surprised/disappointed that MicroPython follows the same
routine, I'm glad I now understand ins and outs of the choices made.
>  https://bugs.python.org/issue1631942
Paul mailto:pmiscml at gmail.com
More information about the Python-Dev