[Python-ideas] PEP 532: A circuit breaking operator and protocol

Nick Coghlan ncoghlan at gmail.com
Sun Nov 13 01:51:14 EST 2016
On 13 November 2016 at 02:57, David Mertz <mertz at gnosis.cx> wrote:
> If recommend 'valued(foo)'. Without the final 'd' I think of "the value of
> foo" rather than "does foo have a value?" Obviously, the value of foo is
> just spelled 'foo' in Python, but it seems confusing.
>
> 'exists(foo)' is even more confusing since almost everyone will read it as
> "is foo defined?" I know you can't do that with a call in Python, but you
> can in lots of other languages.

Right, I was actually persuaded by Steven's argument that PEP 532
would work better if it didn't propose competing directly with PEP 505
at all, and instead positioned itself as providing the underlying
conceptual unification between that PEP and the existing
short-circuiting operators. Updating the PEP draft to work along those
lines is making me thing it's a good direction to take.

The key benefit of that approach in relation to `??` specifically is
that rather than trying to find circuit breaker names that are short
and suggestive, we can just name them literally in the operator module
such that "LHS ?? RHS" becomes equivalent to
"operator.is_not_none(LHS) else RHS".

At that point, if we did decide to offer a builtin instead of
dedicated syntax, the option I'd argue for is actually SQL's
"coalesce":

    coalesce(EXPR1) else coalesce(EXPR2) else EXPR3

Yes, it's computer science jargon, but the operation itself is an odd
one that doesn't really have an established mathematical precedent or
grammatical English equivalent.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list