[Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

Thautwarm Zhao yaoxiansamma at gmail.com
Sun Apr 15 11:11:37 EDT 2018


>
>
> 0.
>
> while (items[i := i+1] := read_next_item()) is not None:
>     print(r'%d/%d' % (i, len(items)), end='\r')
>
> 1.
>
> while (read_next_item() -> items[(i+1) -> i]) is not None:
>     print(r'%d/%d' % (i, len(items)), end='\r')
>
> 2.
>
> while (item := read_next_item()) is not None:
>     items[i := (i+1)] = item
>     print(r'%d/%d' % (i, len(items)), end='\r')
>
> 3.
>
> while (read_next_item() -> item) is not None:
>     items[(i+1) -> i] = item
>     print(r'%d/%d' % (i, len(items)), end='\r')
>
> 4.
>
> while (item := read_next_item()) is not None:
>     i = i+1
>     items[i] = item
>     print(r'%d/%d' % (i, len(items)), end='\r')
>
> 5.
>
> while (read_next_item() -> item) is not None:
>     i = i+1
>     items[i] = item
>     print(r'%d/%d' % (i, len(items)), end='\r')
>
>
Also 2 or 3.
The 3rd one is in the order of natural language, just like:
    while get then next item and assign it to `item`, if it's not None, do
some stuff.

However just as we have pointed out, the semantics of '->' is quite
different from the cases it's currently used at, so it should be handled
much more carefully.

I think maybe we can use unicode characters like ≜ (\triangleq) and add the
support of unicode completion to python repl. The unicode completion of
editors or ides has been quite mature.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180415/3883c27d/attachment.html>


More information about the Python-ideas mailing list