[Python-ideas] PEP 505 (None coalescing operators) thoughts

Carl Meyer carl at oddbird.net
Mon Sep 28 22:00:47 CEST 2015

On 09/28/2015 01:53 PM, Guido van Rossum wrote:
> On Mon, Sep 28, 2015 at 12:43 PM, Carl Meyer <carl at oddbird.net
>     Or put differently, that whereas these two are trivially equivalent (the
>     definition of left-to-right binding within a precedence class):
>         foo.bar.baz
>         (foo.bar).baz
>     these two are not equivalent:
>        foo?.bar.baz
>        (foo?.bar).baz
> Right.
>     I'm having trouble coming up with a parallel example where the existing
>     short-circuit operators break "extractibility" of a sub-expression like
>     that.
> Why is that an interesting property?

Because breaking up an overly-complex expression into smaller
expressions by means of extracting sub-expressions into temporary
variables is a common programming task (in my experience anyway --
especially when trying to decipher some long-gone programmer's
overly-complex code), and it's usually one that can be handled pretty
mechanically according to precedence rules, without having to consider
that some operators might have action-at-a-distance beyond their precedence.

>     I guess this is because the proposed short-circuiting still "breaks out
>     of the precedence order" in a way that the existing short-circuiting
>     operators don't. Both member access and indexing are within the same
>     left-to-right binding precedence class, but the new operators would have
>     a short-circuit effect that swallows operations beyond where normal
>     left-to-right binding would suggest their effect should reach.
>     Are there existing examples of behavior like this in Python that I'm
>     missing?
> I don't know, but I think you shouldn't worry about this.

I think it's kind of odd, but if nobody else is worried about it, I
won't worry about it either :-)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150928/87930f67/attachment.sig>

More information about the Python-ideas mailing list