← 返回首页
gh-82012: Deprecate bitwise inversion (~) of bool by timhoffm · Pull Request #103487 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

gh-82012: Deprecate bitwise inversion (~) of bool#103487

Merged
hauntsaninja merged 5 commits into
python:mainfrom
timhoffm:deprecate-bool-invert
May 3, 2023
Merged

gh-82012: Deprecate bitwise inversion (~) of bool#103487
hauntsaninja merged 5 commits into
python:mainfrom
timhoffm:deprecate-bool-invert

Conversation

timhoffm commented Apr 12, 2023
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

The bitwise inversion operator on bool returns the bitwise inversion of the underlying int value; i.e. ~True == -2 such that bool(~True) == True.

It's a common pitfall that users mistake ~ as negation operator and actually want not. Supporting ~ is an artifact of bool inheriting from int. Since there is no real use-case for the current behavior, let's deprecate ~ on bool and later raise an error. This removes a potential source errors for users.

Full reasoning: #82012 (comment)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Footer

© 2026 GitHub, Inc.