[Python-ideas] PEP-505: Draft (Coalescing Operators)
Mark E. Haase
mehaase at gmail.com
Thu Oct 22 18:36:07 CEST 2015
Yes, that `or` example is incorrect. I have short circuiting and precedence
jumbled up in my head, but thinking about that example has improved my
understanding.
I will fix that and incorporate your other notes shortly.
Thanks!
On Thu, Oct 22, 2015 at 12:13 PM, Guido van Rossum <guido at python.org> wrote:
> 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)
>
--
Mark E. Haase
202-815-0201
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151022/24232130/attachment-0001.html>
More information about the Python-ideas
mailing list