New submission from Tomer Vromen <tom...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue37831> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com