[Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

Kirill Balunov kirillbalunov at gmail.com
Mon Mar 26 04:14:43 EDT 2018


Hi Chris, would you mind to add this syntactic form `(expr -> var)` to
alternative syntax section, with the same semantics as `(expr as var)`. It
seems to me that I've seen this form previously in some thread (can't find
where), but it does not appear in alt. syntax section. As for me this form
has several benefits:
    1. Currently it is a SyntaxError
Really there exist some intersection with syntax to annotate function
return type, but it has much smaller impact than `as` variant.
    2. This form looks It looks as readable (also the expression comes
first, which appeals to me) as the 'as' variant.
    3. It is clearly distinguishable from the usual assignment statement
(which also appeals to me)
Suppose someday someone will want to have a type hint on a local variable
(I think sublocal are safer on this part), then:
```
while (x: int := counter):
do_some_stuff
```
vs
```
while (counter -> x: int):
    do_some_stuff
```
Maybe it is too subjective, but the second form looks better for me. taking
in all the аdvantages of the `as` form. Also this '->' form can be extended
to some sort of tuple unpacking. I don't think that tuple unpacking is a
good example, but nevertheless:) And will make further attempts to
introduce ` +:=` impossible.

With kind regards,
-gdg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180326/df3c7863/attachment-0001.html>


More information about the Python-ideas mailing list