On Wed, Jul 25, 2018 at 10:50 PM Nicholas Chammas <nicholas.chammas@gmail.com> wrote:
Indeed. Thanks for the counter-example. I think the correct translation is as follows:
    food = spam?.eggs?.bacon
Becomes:
    food = None
    if spam is not None and spam.eggs is not None:
        food = spam.eggs.bacon 
Did I get it right now? :)

Nope, still not right, I'm afraid! 

Chris Angelica provided a more accurate translation.  Do you not see that the fact that your *second* try at understanding the actual behavior is still wrong suggest that this operator is a HUGE bug magnet?!
 
So, shame on me. I think this particular mistake reflects more on me than on PEP 505, but I see how this kind of mistake reflects badly on the folks advocating for the PEP (or at least, playing devil's advocate).

I really, really don't.  I think you see an intuitive behavior that would be nice and useful in a certain area.  That behavior just isn't what the PEP proposes though... it's kinda-sorta close enough to be lured into thinking it's a good idea.

Honestly, I think the behavior of GreedyAccess in my little library I wrote over the last couple nights is FAR more often what programmers ACTUALLY want than NullCoalesce is.  Even Steve Dower—in the PEP and in this discussion—acknowledges the appeal and utility of the GreedyAccess behavior.  It's in the "Rejected Ideas" section, which is fair enough.

But in a library like mine... or indeed, in a much better library that you or someone else writes... it's perfectly easy to have both classes, and choose which behavior is more useful for your case.  A new syntax feature can't let user decide which behavior (or maybe some other behavior altogether) is most useful for their specific case.  A library does that easily[*].

[*] In version 0.1.1 of coalescing—changed from 0.1—I added the option to use a sentinel other than None if you want.  I'm not sure how useful that is, but that idea was in some old PEPs, and I think in the Rejected Ideas of 505.  With a library, I have a parameter that need not be used to switch that[**].  E.g.:

NullCoalesce(foo, sentinel=float('nan')).bar.baz.blam

[**] Yes, I even handle NaN's in a special way because they are non-equal even to themselves.  You could use empty string, or 0, or my_null = object(), or whatever.
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.