<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 28, 2015 at 12:43 PM, Carl Meyer <span dir="ltr"><<a href="mailto:carl@oddbird.net" target="_blank">carl@oddbird.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 09/28/2015 12:38 PM, Guido van Rossum wrote:<br>
> On Mon, Sep 28, 2015 at 10:38 AM, Carl Meyer <<a href="mailto:carl@oddbird.net">carl@oddbird.net</a><br>
<br>
</span><span class="">>     "Propagating" refers to the proposed behavior where use of ?. or ?[<br>
>     "propagates" through the following chain of operations. For example:<br>
><br>
>         x = foo?.bar.spam.eggs<br>
><br>
>     Where both `.spam` and `.eggs` would behave like `?.spam` and `?.eggs`<br>
>     (propagating None rather than raising AttributeError), simply because a<br>
>     `.?` had occurred earlier in the chain. So the above behaves differently<br>
>     from:<br>
><br>
>         temp = foo?.bar<br>
>         x = temp.spam.eggs<br>
><br>
>     Which raises questions about whether the propagation escapes<br>
>     parentheses, too:<br>
><br>
>         x = (foo?.bar).spam.eggs<br>
><br>
> Oh, I see. That's evil.<br>
><br>
> The correct behavior here is that "foo?.bar.spam.eggs" should mean the<br>
> same as<br>
><br>
>     (None if foo is None else foo.bar.spam.eggs)<br>
><br>
> (Stop until you understand that is *not* the same as either of the<br>
> alternatives you describe.)<br>
<br>
</span>I see that. The distinction is "short-circuit" vs "propagate."<br>
Short-circuit is definitely more comprehensible and palatable.<br></blockquote><div><br></div><div>Right.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
[snip]<br>
<span class="">> It should not escape parentheses.<br>
<br>
</span>Good. I assume that the short-circuiting would follow the precedence<br>
order; that is, nothing with looser precedence than member and index<br>
access would be short-circuited. So, for example,<br>
<br>
    foo?.bar['baz'].spam<br>
<br>
would short-circuit the indexing and the final member access, translating to<br>
<br>
    foo.bar['baz'].spam if foo is not None else None<br>
<br>
but<br>
<br>
    foo?.bar or 'baz'<br>
<br>
would mean<br>
<br>
    (foo.bar if foo is not None else None) or 'baz'<br>
<br>
and would never evaluate to None. Similarly for any operator that binds<br>
less tightly than member/index access (which is basically all Python<br>
operators).<br></blockquote><div><br></div><div>Correct. The scope of ? would be all following .foo, .[stuff], or .(args) -- but stopping at any other operator (including parens).<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
AFAICS, under your proposed semantics what I said above is still true, that<br>
<br>
    x = foo?.bar.baz<br>
<br>
would necessarily have a different meaning than<br>
<br>
    temp = foo?.bar<br>
    x = temp.baz<br>
<br>
Or put differently, that whereas these two are trivially equivalent (the<br>
definition of left-to-right binding within a precedence class):<br>
<br>
    foo.bar.baz<br>
    (foo.bar).baz<br>
<br>
these two are not equivalent:<br>
<br>
   foo?.bar.baz<br>
   (foo?.bar).baz<br></blockquote><div><br></div><div>Right.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm having trouble coming up with a parallel example where the existing<br>
short-circuit operators break "extractibility" of a sub-expression like<br>
that.<br></blockquote><div><br></div><div>Why is that an interesting property?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I guess this is because the proposed short-circuiting still "breaks out<br>
of the precedence order" in a way that the existing short-circuiting<br>
operators don't. Both member access and indexing are within the same<br>
left-to-right binding precedence class, but the new operators would have<br>
a short-circuit effect that swallows operations beyond where normal<br>
left-to-right binding would suggest their effect should reach.<br>
<br>
Are there existing examples of behavior like this in Python that I'm<br>
missing?</blockquote><div><br></div><div>I don't know, but I think you shouldn't worry about this.<br></div><div> </div></div>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>