[Python-Dev] Compilation of "except FooExc as var" adds useless store

Brett Cannon brett at python.org
Sun Jan 6 15:17:47 EST 2019


On Sun, 6 Jan 2019 at 10:26, Guido van Rossum <guido at python.org> wrote:

> On Sun, Jan 6, 2019 at 9:40 AM Paul G <paul at ganssle.io> wrote:
>
>> I am not familiar enough with the compiler logic, but would it be
>> possible to optimize this away by detecting whether the bound name has
>> already been deleted during the body of the except statement?
>>
>
> As was said before, it's not useful to optimize code that only runs on an
> exception. (Though if there was a
>
> On January 6, 2019 4:18:00 PM UTC, Chris Angelico <rosuav at gmail.com>
> wrote:
>>
>> On Mon, Jan 7, 2019 at 3:13 AM Paul G <paul at ganssle.io> wrote:
>>
>>>
>>>  I think Serhiy is saying that if you delete exc before the except body ends, when the compiled code goes to delete it it will fail. Binding to None guarantees that there is something to delete.
>>>
>>
>> Ahh! Thank you. I interpreted that example as a "this is what it
>> compiles to", rather than actual source code that might fail. Can we
>> get this example, suitably annotated, into the documentation
>> somewhere?
>>
>>
> I don't see a reason to document this behavior -- it would be strange if
> it *didn't* work.
>
> If we had an opcode to delete a variable but didn't raise if it is unset,
> we could use that, but otherwise I see no action needed here.
>

Maybe someone can propose a code comment to explain this instead? I agree
that this doesn't need to be explained in the language spec, but I don't
see any harm in a comment where the opcodes are emitted to explain why it
is the way it is .
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20190106/df49faca/attachment.html>


More information about the Python-Dev mailing list