[Python-ideas] Null coalescing operator
Stephen J. Turnbull
turnbull.stephen.fw at u.tsukuba.ac.jp
Sat Sep 10 12:48:59 EDT 2016
Steven D'Aprano writes:
> As Zach and MRAB mention, this was discussed last year. If I recall
> correctly, the discussion fizzled out without a solid conclusion. I
> think there's a PEP -- if not, there should be.
The problem, as I recall, was that there was a conclusion that
'maybe_None if maybe_None is None else default' and the less precise
'maybe_falsy or default' are sufficient if you just want to provide a
default if a value is "null". The proponents pointed out that other
operators would benefit from null coalescing, and then discussion
petered out because there was no remotely plausible suggestion except
to use '?' to indicate null-coalescing versions. But Guido has
historically resisted any use of '?' whatsoever in Python syntax, and
there weren't any good alternatives or strong proponents of ?-based
syntax.
I forget if Guido was very sympathetic to null-coalescing operators,
given somebody came up with a good syntax.
There was also an issue of whether SQL NULLs and similar constructs
"should" be spelled None in Python, and if not, how would null
coalescence be defined.
Steve
More information about the Python-ideas
mailing list