[Python-ideas] Coming up with an alternative to PEP 505's None-aware operators

Nick Coghlan ncoghlan at gmail.com
Fri Feb 16 06:02:03 EST 2018


On 16 February 2018 at 18:36, Kirill Balunov <kirillbalunov at gmail.com> wrote:
> What about (| val = get_value(x) |) assignment expression which will be True
> if success, and None if not?
>
> So it will be value = f() if (| f = calculate |) else default…The idea is
> inspired from C’s assignment, but needs some special treatment for anything
> which is False in boolean context.

If we're going to allow arbitrary embedded assignments, then "(expr as
name)" is the most likely spelling, since:

* "as" is already a keyword
* "expr as name" is already used for name binding related purposes
(albeit not for simple assignments)
* "python as expression" and "python as keyword" are both things
search engines will accept as queries (search engines tend not to cope
very well when you try to search for punctuation characters)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list