[Python-Dev] Compilation of "except FooExc as var" adds useless store
Paul Sokolovsky
pmiscml at gmail.com
Sun Jan 6 13:48:39 EST 2019
Hello,
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 [1] and the thread with the subject "self-contained
> exceptions" on the Python-3000 mailing list [2] for the rationale.
>
> In short, the code
>
> try:
> 1/0
> 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
references, Serhiy!
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.
>
> [1] https://bugs.python.org/issue1631942
> [2]
> https://mail.python.org/pipermail/python-3000/2007-January/005294.html
--
Best regards,
Paul mailto:pmiscml at gmail.com
More information about the Python-Dev
mailing list