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

Andrew Barnert abarnert at yahoo.com
Wed Sep 30 23:40:15 CEST 2015

On Sep 30, 2015, at 13:58, Piotr Duda <duda.piotr at gmail.com> wrote:
> What about something like:
> z = x if is not None else []

For something as simple as "x", this doesn't seem much better than what we can already do:

    z = x if x is not None else []

For a complex expression that might be incorrect/expensive/dangerous to call multiple times, it might be useful, but I think it would read a lot better with an explicit pronoun:

    z = dangerous_thing(arg) if it is not None else []

In natural languages, "it" is already complex enough; adding in subject elision makes parsing even harder. I think the same would be true here.

Also, explicit "it" would be usable in other situations:

    z = dangerous_thing(arg) if it.value() > 3 else DummyValue(3)

And it gives you something to look up in the docs: help(it) can tell me how to figure out what "it" refers to, but how would I find that out with your version?

Anyway, I still don't like it even with the explicit pronoun, but maybe that's just AppleScript flashbacks. :)

More information about the Python-ideas mailing list