<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 4 September 2016 at 12:52, Mark Shannon <span dir="ltr"><<a href="mailto:mark@hotpy.org" target="_blank">mark@hotpy.org</a>></span> wrote:<span class=""></span><br><span class=""></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
The key difference is in placement.<br>
PEP 484 style<br>
variable = value # annotation<br>
<br>
Which reads to me as if the annotation refers to the value.<br>
PEP 526<br>
variable: annotation = value<br>
<br>
Which reads very much as if the annotation refers to the variable.<br>
That is a change in terms of semantics and a change for the worse, in terms of expressibility.</blockquote></div><br></div><div class="gmail_extra">I still think it is better to leave the decision to type checkers.<br>The proposed syntax allows two forms:<br><br></div><div class="gmail_extra">variable: annotation = value<br><br></div><div class="gmail_extra">and<br><br></div><div class="gmail_extra">variable: annotation<br><br></div><div class="gmail_extra">The first form still could be interpreted by type checkers <br>as annotation for value (a cast to more precise type):<br><br></div><div class="gmail_extra">variable = cast(annotation, value) # visually also looks similar<br><br></div><div class="gmail_extra">and PEP says that annotations "are intended to help with
type inference in complex cases".<br></div><div class="gmail_extra">Such interpretation could be useful for function local variables<br>(the implementation is also optimised for such use case).<br>While the second form (without value)<br></div><div class="gmail_extra">indeed looks like annotation of variable, and is equivalent to:<br><br></div><div class="gmail_extra">__annotations__['variable'] = annotation<br></div><div class="gmail_extra"><br>This form could be useful for annotating instance/class variables.<br></div><div class="gmail_extra">Or just for documentation (I really like this).<br><br></div><div class="gmail_extra">In addition, expression annotations are allowed<br><br></div><div class="gmail_extra">expression: annotation [= value]<br><br></div><div class="gmail_extra">This form is not used by 3rd party tools (as far as I know) but one of the possible use cases<br></div><div class="gmail_extra">could be "check-points" for values:<br><br></div><div class="gmail_extra">somedict[somefunc(somevar)]: annotation # type checker could flag this if something went wrong.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Finally, I would like to reiterate, both interpretations (annotating value vs annotating variable) <br>are possible and we (OK at least me, but it looks like Guido also agree)<br>don't want to force 3rd party tools to use only one of those.<br><br>--<br></div><div class="gmail_extra">Ivan<br><br></div></div>