Mark Dickinson <dicki...@gmail.com> added the comment:
For instances of `int`, `~` does bitwise negation (with the usual two's-complement with an infinite number of bits model that Python uses for all bitwise operations on arbitrary-precision integers). And rightly or wrongly, `True` and `False` are instances of `int`, so it should be possible to use `True` almost anywhere you'd usually use `1`, with no change in behaviour. The proposed change would give us `True == 1` but `~True != ~1`. So I think we're stuck with the current behaviour. Given a time machine, this could arguably be "fixed" by making `True` equal to `-1` rather than `1` ... But absent that time machine, I'd expect some amount of breakage from the proposed change. It's worth noting that NumPy's `bool_` type _does_ do this: >>> import numpy as np >>> ~np.bool_(True) False >>> ~np.bool_(False) True But `np.bool_` doesn't have the same "is-a" relationship with integers: >>> np.bool_.__mro__ (<class 'numpy.bool_'>, <class 'numpy.generic'>, <class 'object'>) IOW, -1 from me. ---------- nosy: +mark.dickinson _______________________________________ 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