On Tue, Feb 23, 2021 at 12:14 PM Soni L. <fakedme+py@gmail.com> wrote:
Currently ~False is -1 and ~True is -2. Would be nicer if ~bool was the same as not bool. Hopefully nobody actually relies on this but nevertheless, it would be a backwards-incompatible change so the whole deprecation warnings and whatnot would be required.
There are quite a few ways in which bitwise operators are not the same as boolean operators. What would be the advantage of having them be the same in just this one case?
In particular, this is nice for xnor operator: a ^~ b. This currently works on ints, but not on bools, while most other operators, including xor, do successfully work on bools.
You could write it as a ^ (not b), as long as you don't mind it giving back an integer rather than a bool. Fundamentally, you're doing bitwise operations on integers, and expecting them to behave as if they have only a single bit each, so another way to resolve this might be to mask it off at the end with "& 1". If this makes your code horrendously ugly, perhaps it would be better to create your own "one-bit integer" class, which responds to all bitwise operators by automatically masking down to one bit? ChrisA