Message349452
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. |
|
Date |
User |
Action |
Args |
2019-08-12 10:48:52 | tomerv | set | recipients:
+ tomerv |
2019-08-12 10:48:52 | tomerv | set | messageid: <1565606932.6.0.360898799273.issue37831@roundup.psfhosted.org> |
2019-08-12 10:48:52 | tomerv | link | issue37831 messages |
2019-08-12 10:48:52 | tomerv | create | |
|