<br><div class="gmail_extra"><div class="gmail_quote">On Wed, Dec 5, 2012 at 8:17 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">On Tue, Dec 4, 2012 at 1:37 AM, David Townshend <<a href="mailto:aquavitae69@gmail.com">aquavitae69@gmail.com</a>> wrote:<br>
> Just thought of a couple of usages which don't fit into the decorator model.<br>
> The first is using the return annotation for early binding:<br>
><br>
>     def func(seq) -> dict(sorted=sorted):<br>
>         return func.__annotations__['return']['sorted'](seq)<br>
<br>
</div>You've got to be kidding... <br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
> Stangely enough, this seems to run slightly faster than<br>
><br>
>     def func(seq, sorted=sorted):<br>
>         return sorted(seq)<br>
><br>
> My test shows the first running in about 0.376s and the second in about<br>
> 0.382s (python 3.3, 64bit).<br>
<br>
</div>Surely that's some kind of random variation. It's only a 2% difference.<br></blockquote><div><br>It's consistent.  I ran several tests and came out with the same 2% difference every time.<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
IOW, this is not a line of thought to pursue.<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br>I wasn't suggesting that this is a good idea, I was merely trying to point out that there are currently ways of using annotations beyond type declarations with decorators, and that there may be other use cases out there which will work well.  Documenting recommendations that annotations only be used with decorators, or only be used for type declarations will limit the possibilities because nobody will bother to look further, and if they do, the ideas will no doubt be shut down as being bad style because they go against the recommended usage.  I thought that limiting annotations like this was what you wanted to avoid?<br>

<br>Having said that, I've never found a good use for annotations in my own code, so I'm not emotionally invested one way or the other.  I do think that the best usage I've seen is exactly what is being discussed here and it would be great if there was some prescribed use for annotations.  Perhaps people would actually use them then.<br>

<br>David<br></div></div></div>