This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients mark.dickinson, tomerv
Date 2019-08-12.11:59:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1565611178.74.0.588507924592.issue37831@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-08-12 11:59:38mark.dickinsonsetrecipients: + mark.dickinson, tomerv
2019-08-12 11:59:38mark.dickinsonsetmessageid: <1565611178.74.0.588507924592.issue37831@roundup.psfhosted.org>
2019-08-12 11:59:38mark.dickinsonlinkissue37831 messages
2019-08-12 11:59:38mark.dickinsoncreate