Skip to content

gh-122982: Extend the deprecation period for bool inversion by two years #123306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Doc/deprecations/pending-removal-in-3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.)
Expand Down
1 change: 0 additions & 1 deletion Doc/deprecations/pending-removal-in-future.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Extend the deprecation period for bool inversion (``~``) by two years.
4 changes: 2 additions & 2 deletions Objects/boolobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
Loading