On Mon, Sep 28, 2015 at 12:53 PM, Carl Meyer <carl@oddbird.net> wrote:
On 09/28/2015 01:43 PM, Carl Meyer wrote:
[snip]
> I assume that the short-circuiting would follow the precedence
> order; that is, nothing with looser precedence than member and index
> access would be short-circuited. So, for example,
>
>     foo?.bar['baz'].spam
>
> would short-circuit the indexing and the final member access, translating to
>
>     foo.bar['baz'].spam if foo is not None else None
>
> but
>
>     foo?.bar or 'baz'
>
> would mean
>
>     (foo.bar if foo is not None else None) or 'baz'
>
> and would never evaluate to None. Similarly for any operator that binds
> less tightly than member/index access (which is basically all Python
> operators).

For a possibly less-intuitive example of this principle (arbitrarily
picking the operator that binds next-most-tightly), what should

    foo?.bar**3

mean?

It's nonsense -- it means (foo?.bar)**3 but since foo?.bar can return None and None**3 is an error you shouldn't do that. But don't try to then come up with syntax that rejects foo?.bar**something statically, because something might be an object implements __rpow__.

And I still don't see why this "principle" would be important.

--
--Guido van Rossum (python.org/~guido)