[Python-Dev] Compilation of "except FooExc as var" adds useless store
pmiscml at gmail.com
Sun Jan 6 06:40:43 EST 2019
On Sun, 6 Jan 2019 22:19:39 +1100
Chris Angelico <rosuav at gmail.com> wrote:
> > It's clear that what happens there is that first None is stored to
> > N, just to del it as the next step. Indeed, that's what done in the
> > compile.c:
> > https://github.com/python/cpython/blob/master/Python/compile.c#L2905
> > Storing None looks superfluous.
> > There's no clear explanation why it's done like that, so probably an
> > artifact of the initial implementation.
> With something as clearly deliberate as this, it's generally safe to
> assume there's a good reason for it.
Absolutely, and one doesn't need to look far for an example. For 20
years Python was devoid of ":=", then, suddenly... ;-).
> But I would very much like to see
> that reason documented, preferably with an example of something that
> could otherwise fail.
Yeah, I'm keen to know too!
> > So, perhaps the change should be not removing "e = None" part, but
> > conversely, removing the "del e" part.
> No, there's a good reason for having the "del e", and that's to
> prevent reference loops
So, I'm not sure if I made that clear, but the issue is that currently
the generated code tries to break the reference loop *twice*. But once
should be enough. And which one of "N = None" or "del N" is better is
something to consider.
Paul mailto:pmiscml at gmail.com
More information about the Python-Dev