diff options
author | Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> | 2023-05-03 07:00:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 07:00:42 (GMT) |
commit | fdb3ef8c0f94c7e55870a585dc6499aca46f9f90 (patch) | |
tree | 8a2c2ce856fe00afc77a99049f3bfa331068069d /Doc/whatsnew | |
parent | 5b05b013ff13032ffc4db07108a507c08b3a604d (diff) | |
download | cpython-fdb3ef8c0f94c7e55870a585dc6499aca46f9f90.zip cpython-fdb3ef8c0f94c7e55870a585dc6499aca46f9f90.tar.gz cpython-fdb3ef8c0f94c7e55870a585dc6499aca46f9f90.tar.bz2 |
gh-82012: Deprecate bitwise inversion (~) of bool (#103487)
The bitwise inversion operator on bool returns the bitwise inversion of the
underlying int value; i.e. `~True == -2` such that `bool(~True) == True`.
It's a common pitfall that users mistake `~` as negation operator and actually
want `not`. Supporting `~` is an artifact of bool inheriting from int. Since there
is no real use-case for the current behavior, let's deprecate `~` on bool and
later raise an error. This removes a potential source errors for users.
Full reasoning: https://github.com/python/cpython/issues/82012#issuecomment-1258705971
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/3.12.rst | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index a3fce7c..5f8a1f0 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -710,6 +710,12 @@ Deprecated replaced by :data:`calendar.Month.JANUARY` and :data:`calendar.Month.FEBRUARY`. (Contributed by Prince Roshan in :gh:`103636`.) +* The bitwise inversion operator (``~``) on bool is deprecated. It will throw an + error in Python 3.14. Use ``not`` for logical negation of bools instead. + In the rare case that you really need the bitwise inversion of the underlying + ``int``, convert to int explicitly with ``~int(x)``. (Contributed by Tim Hoffmann + in :gh:`103487`.) + Pending Removal in Python 3.13 ------------------------------ |