[Python-ideas] Break the dominance of boolean values in boolean context

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Sep 13 01:59:39 CEST 2011


Lukas Lueg wrote:

> The expression "if x == 1 or y == 1" would then become equivalent to
> 
> tmp1 = x.__eq__(1)
> if tmp1:
>  return tmp1
> tmp2 = y.__eq__(1)
> if tmp2:
>  return tmp2
> return = tmp1.__bor__(tmp2)

This scheme would be of limited usefulness. It still assumes
that the operands *can* be treated as boolean values, which
is not always the case --  numpy arrays can't, for example.
Also, the short-circuiting behaviour is still defined by
their boolean values.

I suggested a more complete way of addressing this in
PEP 335.

-- 
Greg



More information about the Python-ideas mailing list