On 31 August 2016 at 15:40, Guido van Rossum <gu...@python.org> wrote:
> On Tuesday, August 30, 2016, Nick Coghlan <ncogh...@gmail.com> wrote:
>> What if we included local variable annotations in func.__annotations__
>> as cells, like the entries in func.__closure__?
>>
>> We could also use that as a micro-optimisation technique: once the
>> type annotation cell is populated, CPython would just use it, rather
>> than re-evaluating the local variable type annotation expression every
>> time the function is called.
>
> But what runtime use have the annotations on locals? They are not part of
> any inspectable interface. I don't want to spend any effort on them at
> runtime. (Just the bit that they are treated as locals.)

I guess as long as they're included somewhere in the AST for the
function body, I don't mind if the translation to bytecode throws them
away - that's essentially saying that a function level type annotation
is effectively interpreted as if it was:

    if False:
        __annotations__[<varname>] = <annotation>

So the code generator will pick up syntax errors during normal
execution, but not runtime errors (since the expression never actually
gets evaluated).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to