[Python-ideas] PEP 572: Statement-Local Name Bindings, take three!
Steven D'Aprano
steve at pearwood.info
Mon Mar 26 07:18:23 EDT 2018
On Mon, Mar 26, 2018 at 11:14:43AM +0300, Kirill Balunov wrote:
> 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.
That was probably my response to Nick:
https://mail.python.org/pipermail/python-ideas/2018-March/049472.html
I compared four possible choices:
target = default if (expression as name) is None else name
target = default if (name := expression) is None else name
target = default if (expression -> name) is None else name
target = default if (name <- expression) is None else name
The two arrow assignment operators <- and -> are both taken from R.
If we go down the sublocal scope path, which I'm not too keen on, then
Nick's earlier comments convince me that we should avoid "as". In that
case, my preferences are:
(best) -> := <- as (worst)
If we just bind to regular locals, then my preferences are:
(best) as -> := <- (worst)
Preferences are subject to change :-)
--
Steve
More information about the Python-ideas
mailing list