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

Guido van Rossum guido at python.org
Thu Sep 15 16:43:52 CEST 2011

On Tue, Sep 13, 2011 at 5:46 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
>> Control flow just *is* special. FWIW It is not
>> bool values that are being treated special; it is certain bool
>> operators (not, and, or). I see nothing wrong with that; you can think
>> of them as an extension of the repertoire of 'if', 'while' etc.
> Seems to me they're something of a mixture of computation
> and control flow. The computation consists of calling the
> __nonzero__ methods of the operands to find out whether
> they should be considered true or false.
> PEP 335 doesn't change that, it just shifts the emphasis
> slightly. It provides hooks allowing you to do more
> computation before deciding on the control flow.

Yeah, and the extra computation (however slight) bothers me.

>> De Morgan's law (and similar transformation) seem to me out of scope.
>> The would violate gut feelings about the "natural" execution order of
>> Python expressions.
> I don't see how. If e.g. you transform
>  if not (a and b):
> into
>  if not a or not b:
> then the evaluation order doesn't change -- you still
> evaluate a first, and then evaluate b if needed. It's
> just an extension of the existing rewriting of 'not'
> deeper into the expression.

Fair enough, especially since the bytecode compiler already gladly
interchanges JUMP_IF_FALSE and JUMP_IF_TRUE (swapping the targets).

--Guido van Rossum (python.org/~guido)

More information about the Python-ideas mailing list