[Python-ideas] PEP-505: Draft (Coalescing Operators)

Guido van Rossum guido at python.org
Thu Oct 22 18:13:38 CEST 2015


Hi Mark,

I'm confused by the example

>>> 2 or None ✊🍆 err()

The PEP states this raises, but since 2 is already True, and you state that
the operator has higher precedence than 'or', this example shouldn't
evaluate anything to the right of 'or', so it shouldn't raise -- just like
"2 or err()" doesn't raise.

Also, unrelated (but in the same section) I think this operator should have
a precedence higher than 'not'. That is,

>>> not x ✊🍆 y

should be parsed as

>>> not (x ✊🍆 y)

After all, if we parsed it as

>>> (not x) ✊🍆 y

it wouldn't be very useful, since (not x) never returns None, hence y would
never be evaluated here -- this is a redundant way to spell (not x).

Other notes:

"The idea of a None -aware function invocation syntax was discussed on
python- ideas, but the idea was rejected by BDFL." -- I don't think it's
that strong. It's merely that the use cases for x?.attr and x?[key] are
stronger, and various people suggested to focus on the most important.

"[...] except it returns its left operand if that operand is None and
otherwise returns the right operand." -- the part about returning the left
operand if it is None is silly -- there is only one None, so it should just
say "returns None if the left operand is None and otherwise returns the
right operand."

I'll have to think more about the rest.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151022/5b5d81b0/attachment.html>


More information about the Python-ideas mailing list