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

Ian Kelly ian.g.kelly at gmail.com
Thu Apr 7 13:19:10 EDT 2016

On Thu, Apr 7, 2016 at 10:38 AM, Guido van Rossum <guido at python.org> wrote:
> Honestly I think that the OP has a point, and I don't think we have to
> bend over backwards to preserve int compatibility. After all str(True)
> != str(1), and surely there are other examples.

I can see it going either way: if we treat the domain of bool as that
of the integers, then ~True == ~1 == -2.

If on the other hand we treat it as the integers modulo 2, then it
makes sense that ~True == ~1 == 0. But this would also imply that True
+ True == False, which would definitely break existing code.

I note that if you add an explicit modulo division by 2, then it works out:

py> ~True % 2
py> ~False % 2

The salient point to me is that there's no strong justification for
making the change. As has been pointed out elsewhere in the thread, if
you want binary not, just use not.

More information about the Python-ideas mailing list