On Tuesday, August 30, 2016, Nick Coghlan <<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 31 August 2016 at 13:37, Jack Diederich <<a href="javascript:;" onclick="_e(event, 'cvml', 'jackdied@gmail.com')">jackdied@gmail.com</a>> wrote:<br>
> On Tue, Aug 30, 2016 at 11:03 PM, Guido van Rossum <<a href="javascript:;" onclick="_e(event, 'cvml', 'guido@python.org')">guido@python.org</a>> wrote:<br>
>> But myfunc.__annotations__ already exists -- PEP 3107 puts the<br>
>> signature annotations there. The problem with co_annotations is that<br>
>> annotations are evaluated (they can be quite complex expressions, e.g.<br>
>> Optional[Tuple[int, int, some_mod.SomeClass]]), while co_varnames is<br>
>> just a list of strings. And code objects must be immutable. The issue<br>
>> with rejecting duplicate annotations so sternly is the same as for the<br>
>> previous bullet.<br>
>><br>
><br>
> If we disallow re-assignment of types as a syntax error then the conflict<br>
> with myfunc.__annotations__ goes away for vars that share a name with the<br>
> function arguments. The fact that variables with types can't be known until<br>
> the function body executes a particular line is .. I'm not sure how to deal<br>
> with that. For modules and classes you can assert that the body at the top<br>
> indent level has been executed. For functions you can only assert that it<br>
> has been parsed. So myfunc.__annotations__ could say that the type has a<br>
> definition but only later know what the definition is.<br>
<br>
What if we included local variable annotations in func.__annotations__<br>
as cells, like the entries in func.__closure__?<br>
<br>
We could also use that as a micro-optimisation technique: once the<br>
type annotation cell is populated, CPython would just use it, rather<br>
than re-evaluating the local variable type annotation expression every<br>
time the function is called.<br>
</blockquote><div><br></div><div>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.)</div><div><br></div><div>--Guido</div><br><br>-- <br>--Guido (mobile)<br>