gh-134280: Disable constant folding for ~ with a boolean argument (GH… · python/cpython@86c3316 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit 86c3316

Browse files
gh-134280: Disable constant folding for ~ with a boolean argument (GH-134982)
This moves the deprecation warning from compile time to run time.
1 parent e0d6500 commit 86c3316

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

Lib/test/test_peepholer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def test_constant_folding_unaryop(self):
292292
('---x', 'UNARY_NEGATIVE', None, False, None, None),
293293
('~~~x', 'UNARY_INVERT', None, False, None, None),
294294
('+++x', 'CALL_INTRINSIC_1', intrinsic_positive, False, None, None),
295+
('~True', 'UNARY_INVERT', None, False, None, None),
295296
]
296297

297298
for (
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Disable constant folding for ``~`` with a boolean argument.
2+
This moves the deprecation warning from compile time to runtime.

Python/flowgraph.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,10 @@ eval_const_unaryop(PyObject *operand, int opcode, int oparg)
18921892
result = PyNumber_Negative(operand);
18931893
break;
18941894
case UNARY_INVERT:
1895+
// XXX: This should be removed once the ~bool depreciation expires.
1896+
if (PyBool_Check(operand)) {
1897+
return NULL;
1898+
}
18951899
result = PyNumber_Invert(operand);
18961900
break;
18971901
case UNARY_NOT: {

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.