On Wed, Jul 25, 2018 at 11:09 PM David Mertz <mertz@gnosis.cx> wrote:
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.

Forgive me for being slow. I'm missing what's different in semantics between the translation above and Chris's translation below:

_tmp = spam
if _tmp is not None:
    _tmp = _tmp.eggs
    if _tmp is not None:
        _tmp = _tmp.bacon
food = _tmp

What's a case where they would do something different?

* If spam is None, they work the same -> None
* If spam is not None, but spam.eggs exists and is None, they work the same -> None
* If spam is not None, but spam.eggs doesn't exist, they work the same -> AttributeError
* If spam is not None, and spam.eggs is not None, but spam.eggs.bacon is None, they work the same -> None
* If spam is not None, and spam.eggs is not None, but spam.eggs.bacon doesn't exist, they work the same -> AttributeError
* If spam is not None, and spam.eggs is not None, and spam.eggs.bacon is not None, they work the same -> bacon