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

Ben Finney ben+python at benfinney.id.au
Mon Sep 28 22:38:37 CEST 2015

Guido van Rossum <guido at python.org> writes:

> This seems a perfect use case for writing post?.tag.lower() -- this
> signifies that post may be None but if it exists, post.tag is not
> expected to be None. So basically I want the equivalent of
> (post.tag.lower() if post is not None else None).

You're deliberately choosing straightforward examples. That's fine for
showing the intended use case, but it does mean dismissing the concerns
about ambiguity in complex cases.

It also means the use cases are so simply they are easily expressed
succinctly with existing syntax, with the advantage of being more
explicit in their effect; so they don't argue strongly for the need to
add the new syntax.

So, the corner case examples in this thread, which mix up precedence,
are useful because they show how confusion is increased by making the
precedence and binding rules more complicated.

 \           “People are very open-minded about new things, as long as |
  `\         they're exactly like the old ones.” —Charles F. Kettering |
_o__)                                                                  |
Ben Finney

More information about the Python-ideas mailing list