https://github.com/python/cpython/commit/8ba024ddf5678554a04ebd4208baffb07995dd4d
commit: 8ba024ddf5678554a04ebd4208baffb07995dd4d
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2025-07-02T11:28:09+03:00
summary:

[3.14] gh-134280: Disable constant folding for ~ with a boolean argument 
(GH-134982) (GH-136185)

This moves the deprecation warning from compile time to run time.
(cherry picked from commit 86c3316183a79867e3c666d0830f897e16f0f339)

Co-authored-by: Serhiy Storchaka <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2025-05-31-19-24-54.gh-issue-134280.NDVbzY.rst
M Lib/test/test_peepholer.py
M Python/flowgraph.c

diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py
index 41b2e3a395293e..3a232e5ff085fe 100644
--- a/Lib/test/test_peepholer.py
+++ b/Lib/test/test_peepholer.py
@@ -292,6 +292,7 @@ def test_constant_folding_unaryop(self):
             ('---x', 'UNARY_NEGATIVE', None, False, None, None),
             ('~~~x', 'UNARY_INVERT', None, False, None, None),
             ('+++x', 'CALL_INTRINSIC_1', intrinsic_positive, False, None, 
None),
+            ('~True', 'UNARY_INVERT', None, False, None, None),
         ]
 
         for (
diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2025-05-31-19-24-54.gh-issue-134280.NDVbzY.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2025-05-31-19-24-54.gh-issue-134280.NDVbzY.rst
new file mode 100644
index 00000000000000..f822721690975a
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2025-05-31-19-24-54.gh-issue-134280.NDVbzY.rst
@@ -0,0 +1,2 @@
+Disable constant folding for ``~`` with a boolean argument.
+This moves the deprecation warning from compile time to runtime.
diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index cee3e9bd6355a6..8e395b14739d94 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -1884,6 +1884,10 @@ eval_const_unaryop(PyObject *operand, int opcode, int 
oparg)
             result = PyNumber_Negative(operand);
             break;
         case UNARY_INVERT:
+            // XXX: This should be removed once the ~bool depreciation expires.
+            if (PyBool_Check(operand)) {
+                return NULL;
+            }
             result = PyNumber_Invert(operand);
             break;
         case UNARY_NOT: {

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to