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

This moves the deprecation warning from compile time to run time.
This commit is contained in:
Serhiy Storchaka 2025-07-01 20:24:04 +03:00 committed by GitHub
parent e0d6500b2d
commit 86c3316183
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 0 deletions

View 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 (

View file

@ -0,0 +1,2 @@
Disable constant folding for ``~`` with a boolean argument.
This moves the deprecation warning from compile time to runtime.

View file

@ -1892,6 +1892,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: {