[issue37831] bool(~True) == True

Guido van Rossum report at bugs.python.org
Wed Aug 14 10:40:10 EDT 2019


Guido van Rossum <guido at python.org> added the comment:

It never occurred to me that making b&b an b|b return bool would be considered a bad thing just because ~b is not a bool. That's like complaining that 1+1 returns an int rather than a float for consistency with 1/2 returning a float.

Because bool is embedded in int, it's okay to return a bool value *that compares equal to the int from the corresponding int operation*. Code that accepts ints and is passed bools will continue to work. But if we were to make ~b return `not b`, that makes bool not embedded in int (for the sake of numeric operations).

Take for example

def f(a: int) -> int:
    return ~a

I don't think it's a good idea to make f(0) != f(False).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37831>
_______________________________________


More information about the Python-bugs-list mailing list