[Python-ideas] PEP 505 (None coalescing operators) thoughts
Guido van Rossum
guido at python.org
Mon Sep 28 22:54:09 CEST 2015
On Mon, Sep 28, 2015 at 1:38 PM, Ben Finney <ben+python at benfinney.id.au>
> 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.
But your argument seems to boil down to "it is possible to write obfuscated
code using this feature".
If you want to dumb down the feature so that foo?.bar.baz means just
(foo?.bar).baz then it's useless and I should just reject the PEP.
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas