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

Koos Zevenhoven k7hoven at gmail.com
Fri Apr 8 08:28:08 EDT 2016

On Fri, Apr 8, 2016 at 4:40 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Thu, Apr 07, 2016 at 11:08:38AM -0700, Guido van Rossum wrote:
>> 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.
> You missed two: >> and <<. What are we to do with (True << 1)?

Not everyone considers bit shifts 'bitwise', as they don't act at the
level of individual bit positions:


> Honestly, I cannot even imagine what it means to say "shift a truth
> value N bits". I think the idea that bitwise operations on bools are
> actually boolean operations in disguise is not a well-formed idea.
> Sometimes it happens to work out (& | ^), and sometimes it doesn't (<<
> and ~).

One point of view is that bitwise operations should stay within bool,
while shifts return ints, the left-shift operations actually being
much more useful than "left-pad" ;). The main point of >> can be seen
as consistency, although perhaps useless.

That said, I don't really have an opinion on the OP's suggestion.


More information about the Python-ideas mailing list