Closed
Description
Feature or enhancement
Proposal:
Since Python 3.12, attempting to use bitwise inversion on a bool type is raises a DeprecationWarning
:
Python 3.12.4 (main, Jun 6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = True
>>> ~a
<stdin>:1: DeprecationWarning: Bitwise inversion '~' on bool is deprecated. This returns the bitwise inversion of the underlying int object and is usually not what you expect from negating a bool. Use the 'not' operator for boolean negation or ~int(x) if you really want the bitwise inversion of the underlying int.
-2
>>>
I have a PR ready.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
- gh-122982: Prohibit bitwise inversion on bool type #122983
- gh-122982: Extend the deprecation period for bool inversion by two years #123306
- [3.13] gh-122982: Extend the deprecation period for bool inversion by two years (GH-123306) #123316
- [3.12] gh-122982: Extend the deprecation period for bool inversion by two years (GH-123306) #123317