[Python-ideas] PEP 505: None-aware operators
Steven D'Aprano
steve at pearwood.info
Fri Jul 20 13:24:41 EDT 2018
On Thu, Jul 19, 2018 at 10:33:21AM +0200, Antoine Pitrou wrote:
> def insort_right(a, x, lo=0, hi=None):
> # ...
> hi = hi else len(a)
I read that as "hi, if it is truthy, else len(a)".
The advantage of ?? as None-aware operator is that it cannot possibly be
misread as applying to arbitrary falsey objects:
- for those familiar with the equivalent from other languages,
the use of ?? to check for nil/null/None is familiar and obvious;
- for those who aren't, the ?? syntax avoids leading them to guess
the wrong behaviour, as "else" would do.
P.S. I just had to delete 40+ screenfuls of irrelevant quoted text. Come
on folks, please trim your posts! Don't blame your tools.
--
Steve
More information about the Python-ideas
mailing list