]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-134280: Disable constant folding for ~ with a boolean argument (GH-134982...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 2 Jul 2025 08:28:09 +0000 (10:28 +0200)
committerGitHub <noreply@github.com>
Wed, 2 Jul 2025 08:28:09 +0000 (11:28 +0300)
This moves the deprecation warning from compile time to run time.
(cherry picked from commit 86c3316183a79867e3c666d0830f897e16f0f339)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_peepholer.py
Misc/NEWS.d/next/Core_and_Builtins/2025-05-31-19-24-54.gh-issue-134280.NDVbzY.rst [new file with mode: 0644]
Python/flowgraph.c

index 41b2e3a395293e27f64acfb359624c30a2dcc7d2..3a232e5ff085fe4c69797cec7ce3f7f2ddf074c1 100644 (file)
@@ -292,6 +292,7 @@ class TestTranforms(BytecodeTestCase):
             ('---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 (file)
index 0000000..f822721
--- /dev/null
@@ -0,0 +1,2 @@
+Disable constant folding for ``~`` with a boolean argument.
+This moves the deprecation warning from compile time to runtime.
index cee3e9bd6355a686ba7ef2ad2dd32bf17efa2d62..8e395b14739d947a89882acbd7d237228f079126 100644 (file)
@@ -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: {