From e34f925d9c1b7eb045fc249dbb76c32ff7c67203 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 25 Aug 2024 10:57:11 +0300 Subject: [PATCH 1/3] Extend the deprecation period --- Doc/deprecations/pending-removal-in-3.16.rst | 3 +++ Doc/deprecations/pending-removal-in-future.rst | 1 - Doc/whatsnew/3.12.rst | 2 +- Objects/boolobject.c | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-3.16.rst b/Doc/deprecations/pending-removal-in-3.16.rst index de134f8e2ee9d3..e50e3fc1b37cbe 100644 --- a/Doc/deprecations/pending-removal-in-3.16.rst +++ b/Doc/deprecations/pending-removal-in-3.16.rst @@ -5,6 +5,9 @@ Pending Removal in Python 3.16 :class:`array.array` ``'u'`` type (:c:type:`wchar_t`): use the ``'w'`` type instead (``Py_UCS4``). +* :mod:`builtins`: + ``~bool``, bitwise inversion on bool. + * :mod:`symtable`: Deprecate :meth:`symtable.Class.get_methods` due to the lack of interest. (Contributed by Bénédikt Tran in :gh:`119698`.) diff --git a/Doc/deprecations/pending-removal-in-future.rst b/Doc/deprecations/pending-removal-in-future.rst index 6942b9d62cb8f2..ae33236a6cf604 100644 --- a/Doc/deprecations/pending-removal-in-future.rst +++ b/Doc/deprecations/pending-removal-in-future.rst @@ -11,7 +11,6 @@ although there is currently no date scheduled for their removal. * :mod:`builtins`: - * ``~bool``, bitwise inversion on bool. * ``bool(NotImplemented)``. * Generators: ``throw(type, exc, tb)`` and ``athrow(type, exc, tb)`` signature is deprecated: use ``throw(exc)`` and ``athrow(exc)`` instead, diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 3821ee3648e909..a240c1fb4cebe6 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -1319,7 +1319,7 @@ Deprecated (Contributed by Brett Cannon in :gh:`65961`.) * 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. + error in Python 3.16. 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: ``~int(x)``. (Contributed by Tim Hoffmann in :gh:`103487`.) diff --git a/Objects/boolobject.c b/Objects/boolobject.c index fb48dcbeca7850..a88a8ad0cfd560 100644 --- a/Objects/boolobject.c +++ b/Objects/boolobject.c @@ -71,8 +71,8 @@ static PyObject * bool_invert(PyObject *v) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Bitwise inversion '~' on bool is deprecated. This " - "returns the bitwise inversion of the underlying int " + "Bitwise inversion '~' on bool is deprecated and will be removed in " + "Python 3.16. 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 " From e045086d5c1d39d999045a2b484405b7f3fbebf3 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 25 Aug 2024 10:58:57 +0300 Subject: [PATCH 2/3] Add a ``NEWS`` entry --- .../2024-08-25-10-54-22.gh-issue-122982.KLD91q.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-08-25-10-54-22.gh-issue-122982.KLD91q.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-08-25-10-54-22.gh-issue-122982.KLD91q.rst b/Misc/NEWS.d/next/Core and Builtins/2024-08-25-10-54-22.gh-issue-122982.KLD91q.rst new file mode 100644 index 00000000000000..64882df6af10d2 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-08-25-10-54-22.gh-issue-122982.KLD91q.rst @@ -0,0 +1 @@ +Extend the deprecation period for bool inversion (``~``) by two years. From 41246a7a249677a1a44d08532565ae08ce3a3bf3 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 25 Aug 2024 11:04:12 +0300 Subject: [PATCH 3/3] Fix --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 01121feb2b2311..088735bdccab07 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -868,7 +868,7 @@ over ``&``, ``|`` and ``^``. .. deprecated:: 3.12 The use of the bitwise inversion operator ``~`` is deprecated and will - raise an error in Python 3.14. + raise an error in Python 3.16. :class:`bool` is a subclass of :class:`int` (see :ref:`typesnumeric`). In many numeric contexts, ``False`` and ``True`` behave like the integers 0 and 1, respectively.