A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2016-August/146026.html below:

[Python-Dev] PEP 526 ready for review: Syntax for Variable and Attribute Annotations

[Python-Dev] PEP 526 ready for review: Syntax for Variable and Attribute AnnotationsNick Coghlan ncoghlan at gmail.com
Wed Aug 31 06:09:21 EDT 2016
On 31 August 2016 at 15:40, Guido van Rossum <guido at python.org> wrote:
> On Tuesday, August 30, 2016, Nick Coghlan <ncoghlan at 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   |   ncoghlan at gmail.com   |   Brisbane, Australia
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4