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