~bool deprecation

If you use & or | on bools, you get a bool result:

>>> True & True
True
>>> False | False
False

Only when you mix in an int do you get an int:

>>> True & 1
1
>>> False | 0
0

I can see no reason why using ~ with a bool shouldn’t return a bool and complete the set, other than we already have not, except for the fact that there’s no dunder method for not.

numpy uses ~, & and | for arrays of bools because there are no dunders for not, and or or.

1 Like