PEP 308: I liked the original proposal better
Terry Reedy
tjreedy at udel.edu
Mon Feb 24 01:06:40 EST 2003
"Delaney, Timothy C (Timothy)" <tdelaney at avaya.com> wrote in message
news:mailman.1046059565.6975.python-list at python.org...
"class bool:
def ifelse (self, trueresult, falseresult, callable=False):
if self:
if callable:
return trueresult()
else:
return trueresult
else:
if callable:
return falseresult()
else:
return falseresult
Short-circuiting and everything else required in one.
"
With the optional callable arg (which I did not notice in provious
proposals) this makes a lot of sense .... except that other forms do
not require the condition to be a boolean, so this would either
require bool(C).ifelse(x,y) or implementation as a builtin func rather
than method. There is also extra overhead with func/method call. If
one result is constant, and other not, forcing constant to be a
function adds a second layer of call overhead. Still, anyone can add
function version of this to their utility package regardless of PEp
outcome.
Terry J. Reedy
More information about the Python-list
mailing list