FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-149532: Remove `bool.__invert__` magic method by sobolevn · Pull Request #149533 · python/cpython · GitHub

/ cpython Public

gh-149532: Remove bool.__invert__ magic method - #149533

Open
sobolevn wants to merge 1 commit into
python:mainfrom
sobolevn:issue-149532
Open

gh-149532: Remove bool.__invert__ magic method#149533
sobolevn wants to merge 1 commit into
python:mainfrom
sobolevn:issue-149532

Conversation

sobolevn commented May 8, 2026
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

sergey-miryanov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

👍

Comment thread Doc/whatsnew/3.16.rst
* Bitwise inversion on boolean types, ``~True`` or ``~False``
has been deprecated since Python 3.12,
as it produces surprising and unintuitive results (``-2`` and ``-1``).
Use ``not x`` instead for the logical negation of a Boolean.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
Use ``not x`` instead for the logical negation of a Boolean.
Use ``not x`` instead for the logical negation of a boolean.

Comment thread Lib/test/test_bool.py
Comment on lines +160 to +175
msg = re.escape("bad operand type for unary ~: 'bool'")

# Check constants in case of a folding:
with self.assertRaisesRegex(TypeError, msg):
~False
with self.assertRaisesRegex(TypeError, msg):
~True

# Check variable:
for bool_val in [True, False]:
with self.subTest(bool_val), self.assertRaisesRegex(TypeError, msg):
~bool_val

# Check `eval`:
with self.assertRaisesRegex(TypeError, msg):
eval("~False")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Curious if those shouldn't be subtests

sobolevn commented May 9, 2026

Copy link
Copy Markdown
Member Author

See https://discuss.python.org/t/bool-deprecation/62232/128 for the context.

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review DO-NOT-MERGE stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL