[Python-ideas] Changing the meaning of bool.__invert__

Terry Reedy tjreedy at udel.edu
Thu Apr 7 16:05:19 EDT 2016


On 4/7/2016 2:08 PM, Guido van Rossum wrote:
> On Thu, Apr 7, 2016 at 10:39 AM, Michael Selik <mike at selik.org> wrote:

>> To clarify, the proposal is: ``~True == False`` but every other operation on ``True`` remains the same, including ``True * 42 == 42``. Correct?
>
> Yes. To be more precise, there are some "arithmetic" operations (+, -,
> *, /, **) and they all treat bools as ints and always return ints;
> there are also some "bitwise" operations (&, |, ^, ~) and they should
> all treat bools as bools and return a bool. Currently the only
> exception to this idea is that ~ returns an int, so the proposal is to
> fix that. (There are also some "boolean" operations (and, or, not) and
> they are also unchanged.)

When the proposal is expressed as "Make bools consistently follow this 
simple rule -- Logical and 'bitwise' operations on bools return the 
expected bool, while arithmetic operations treat bools as 0 or 1 and 
return ints.", it makes sense to me.

Given that ~bool hardly make any sense currently, I would not expect it 
to be in much use now.  Hence not much to break.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list