122982
Originally, the plan was to move toward a full error or a more aggressive deprecation schedule. However, Issue #122982 proposes . This extension serves a few key purposes:
is_active = True status = ~is_active # Returns -2, triggers warning Use code with caution. Copied to clipboard is_active = True status = not is_active # Returns False Use code with caution. Copied to clipboard Conclusion 122982
Python’s evolution is often about making the "obvious" way to do things the only way to do things. While Issue #122982 might seem like a minor administrative tweak in the CPython GitHub, it reflects the core philosophy of maintaining a stable, readable, and developer-friendly language. Originally, the plan was to move toward a
If your project currently triggers a DeprecationWarning when using ~ on a boolean, the fix is straightforward. Replace the bitwise operator with the logical not keyword: Copied to clipboard is_active = True status =
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
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 .
This blog post addresses in the CPython repository, which focuses on extending the deprecation warning period for bitwise inversion on boolean types in Python.