gh-82012: Deprecate bitwise inversion (~) of bool by timhoffm · Pull Request #103487 · python/cpython

@bedevere-bot mentioned this pull request

Apr 12, 2023

timhoffm

gvanrossum

JelleZijlstra

JelleZijlstra

@timhoffm @JelleZijlstra

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: python#82012 (comment)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

@timhoffm

This also pulls the bool type to top-level of the type
description page. Before it was only documented in the
section "Other Built-in Types / Boolean Values".

JelleZijlstra

hauntsaninja

@timhoffm

hauntsaninja

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>

@timhoffm timhoffm deleted the deprecate-bool-invert branch

May 3, 2023 07:22

pllim

This was referenced

Oct 4, 2023

pllim added a commit to pllim/cpython that referenced this pull request

Oct 4, 2023

@josyb josyb mentioned this pull request

Feb 18, 2024