[New-bugs-announce] [issue37831] bool(~True) == True
Tomer Vromen
report at bugs.python.org
Mon Aug 12 06:48:52 EDT 2019
New submission from Tomer Vromen <tomerv at gmail.com>:
Bitwise operators have inconsistent behavior when acting on bool values: (Python 3.7.4)
# "&" works like "and"
>>> True & True
True
>>> True & False
False
>>> False & False
False
# "|" works like "or"
>>> True | True
True
>>> True | False
True
>>> False | False
False
# "~" does not work like "not"!
>>> ~True
-2
>>> ~False
-1
The result of this is the a user might start working with "&" and "|" on bool values (for whatever reason) and it will work as expected. But then, when adding "~" to the mix, things start to break.
The proposal is to make "~" act like "not" on bool values, i.e. ~True will be False; ~False will be True.
I'm not sure if this has any negative impact on existing code. I don't expect any, but you can never know. If there is no objection to this change, I can even try to implement it myself an submit a patch.
----------
components: Interpreter Core
messages: 349452
nosy: tomerv
priority: normal
severity: normal
status: open
title: bool(~True) == True
type: enhancement
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37831>
_______________________________________
More information about the New-bugs-announce
mailing list