[Python-ideas] [Python-Dev] What's the status of PEP 505: None-aware operators?
Steven D'Aprano
steve at pearwood.info
Wed Nov 29 17:52:02 EST 2017
On Wed, Nov 29, 2017 at 06:49:14AM -0800, David Mertz wrote:
> I didn't say no use case exists, but rather "too special case." And/or
> shortcutting is great, but truthiness feels much more general than noneness
> to me.
Of course truthiness is much more general than Noneness -- and that's
precisely the problem with using `or`. It's too general.
If you haven't read the PEP, you should, because this is extensively
discussed there. One of the problems the author discusses is that `or`
is recommended on Stackoverflow as the best way to perform short-cutting
None tests, often with no caveats given.
We've been here before. Python old-timers may remember the former
idiomatic way to get a ternary if expression:
condition and first or second
which was also buggy (if first happens to be falsey, second is returned
even when condition is true).
--
Steve
More information about the Python-ideas
mailing list