On 7/19/2018 4:33 AM, Antoine Pitrou wrote:
This is adding a whole range of new operators without enough of a use
case. It is also making code harder to read, as evaluation can stop at
any of the "?*" operators. And it looks like noise (or like Perl 6,
which is the same).
There is a use case I sympathize with: the argument-is-None case. For
that I would suggest a simpler form: "A else B" which would evaluate
to A if A is not None, otherwise to B (parentheses may be mandatory).
So e.g. one of the examples would read:
def insort_right(a, x, lo=0, hi=None):
# ...
hi = hi else len(a)
# ...
I like this. (A or B) and (A and B) could now* be explained as an
abbreviations of
A if A else B
A if not A else B
but with A only evaluated once, as in
tem = A; tem if tem else B
tem = A; tem if not A else B
(A if A else B) is equivalent to (A if bool(A) is not False else B)
(A else B) is then easily explained as an abbreviation of
A if A is not None else B
that only evaluates A once.
* In the future, tem if (tem := A) else B
--
Terry Jan Reedy
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/