~bool deprecation

Good question.

For bitmasks, I do use things like flags &= ~(x == 0). For example in my implementation of a special kind of segment tree that I’ve shared with tons of people, I have the line for i in range(n & ~(bit == 0)):, See link to blog.

Could I have coded this differently? Absolutely! But I never expected Python to suddenly make a breaking change by removing ~ from Booleans.

3 Likes