Replace ~ on a bool with ~int()

Proprietary

Bitwise inversion of a bool was deprecated in Python 3.12 and is scheduled for removal in Python 3.16. Replace ~x with ~int(x), which gives the same integer. Where only the result's truth is read, as in if ~x:, the expression is always true, so it is left for a person to fix. Only fires on a bool literal or where the operand's type resolves to bool.

org.openrewrite.python.migrate.ReplaceBitwiseInversionOnBool
mod run . --recipe=org.openrewrite.python.migrate.ReplaceBitwiseInversionOnBool

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.