[issue12447] ~True is not False

Matt Joiner report at bugs.python.org
Thu Jun 30 07:45:42 CEST 2011


New submission from Matt Joiner <anacrolix at gmail.com>:

Given there is no ! operator in Python, I next tried ~ (despite that I'm after a logical not). This came as a surprise:

>>> bool(~True)
True
>>> bool(~False)
True
>>> bool(~~False)
False
>>> ~True, ~~True, ~False, ~~False
(-2, 1, -1, 0)

Is there any consideration to "fixing" this? Is int(True) 1 due to C? Why is it preferred over -1?

It seems more appropriate to me that True have:

def __invert__(self): return False
def __int__(self): return 1 # or even -1

This also "fixes" this case too:

>>> -True
-1

----------
components: Interpreter Core
messages: 139458
nosy: anacrolix
priority: normal
severity: normal
status: open
title: ~True is not False
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12447>
_______________________________________


More information about the Python-bugs-list mailing list