Skip to content

122982

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:

Rapidly turning a warning into a hard error can break environments. A longer warning period ensures developers see the notice without their builds immediately failing. 122982

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 . If your project currently triggers a DeprecationWarning when

This blog post addresses in the CPython repository, which focuses on extending the deprecation warning period for bitwise inversion on boolean types in Python. 122982