122982 [ 2024 ]

In Python, booleans are a subclass of integers. When you apply the bitwise NOT operator ( ~ ) to a boolean: ~True (which is ~1 ) evaluates to -2 . ~False (which is ~0 ) evaluates to -1 .

It allows more time for the community to discuss if there are specific edge cases where bitwise inversion on bool remains necessary. How to Prepare Your Code 122982

This blog post addresses in the CPython repository, which focuses on extending the deprecation warning period for bitwise inversion on boolean types in Python. In Python, booleans are a subclass of integers

Keep an eye on your console for those DeprecationWarnings —they are there to help you stay ahead of the curve! It allows more time for the community to

For most developers, this is rarely the intended result. Usually, someone using ~ on a boolean actually wants the logical NOT ( not True ), which correctly returns False . Because of this common point of confusion, the Python steering committee decided to deprecate bitwise inversion on booleans to encourage clearer coding practices. What’s New in Issue #122982?