# ~bool deprecation

**URL:** <https://discuss.python.org/t/bool-deprecation/62232>\
**Category:** Core Development\
**Created:** [August 28, 2024, 6:49pm UTC](https://discuss.python.org/t/bool-deprecation/62232 "2024-08-28T18:49:37Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![bjorn-martinsson](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bjorn-martinsson/32/8917_2.png) [@bjorn-martinsson](https://discuss.python.org/u/bjorn-martinsson)\
**Post date:** [August 29, 2024, 12:09pm UTC](https://discuss.python.org/t/bool-deprecation/62232/8 "2024-08-29T12:09:26Z")

</div>

I’ve found using `~` to be very useful in many different situations, and I’ve using it a lot, both in Python and C++. I’ve identified 3 cases where my Python code breaks because of this change. Codes involving bitmasks, codes making use of `~` for “reverse indexing” of a list, and the codegolf trick of using `-~x` to increment `x` by 1.

There is a relatively easy workaround, simply search replace `~` with `~+`. The `+` will convert any Boolean to an int.

I’m against deprecating `~` on Booleans in general, but I am strongly against changing `~True` to `False`. A change like that is really dangerous since it could (and would) create silent bugs. It also would make new code incompatible with older versions of Python.

Something I also want to note is that `~` in numpy is **always** bit-inverse. `~0` is always `-1`, even in numpy. However, depending on the data type, `-1` can have different representations. Modulo two, -1 is equal to 1.

---

_[View the full topic](https://discuss.python.org/t/bool-deprecation/62232)._
