[Replying to Steve Dower] On Sat, Sep 03, 2016 at 04:19:13AM +1000, Steven D'Aprano wrote: > On Fri, Sep 02, 2016 at 10:47:41AM -0700, Steve Dower wrote: > > "I'm not seeing what distinction you think you are making here. What > > distinction do you see between: > > > > x: int = func(value) > > > > and > > > > x = func(value) #type: int" > > > > Not sure whether I agree with Mark on this particular point, but the > > difference I see here is that the first describes what types x may > > ever contain, while the latter describes what type of being assigned > > to x right here. So one is a variable annotation while the other is an > > expression annotation.
I see it differently, but I'm quite used to OCaml: # let f () = let x : int = 10 in let x : float = 320.0 in x;; Warning 26: unused variable x. val f : unit -> float = <fun> # f();; - : float = 320. Like in Python, in OCaml variables can be rebound and indeed have different types with different explicit type constraints. Expressions can also be annotated, but require parentheses (silly example): # let x = (10 * 20 : int);; val x : int = 200 So I'm quite happy with the proposed syntax in the PEP, perhaps the parenthesized expression annotations could also be added. But these are only very rarely needed. Stefan Krah _______________________________________________ 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