[issue12647] Add __bool__ to None
Raymond Hettinger
report at bugs.python.org
Wed Jul 27 21:26:16 CEST 2011
New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:
Currently bool(None) returns False only because it has a special case in PyObject_IsTrue(). All other types can become False only if they implement __bool__() or __len__().
I propose removing the special case branch and instead adding __bool__ to None. This will simplify the explanation of what bool() does to: "bool(x) always returns True unless the object defines __bool__() to return False or defines __len__() to return a non-zero value".
The removal of the special case will slightly slow down tests for "if None", and it will slightly speed-up tests for "if x" where x is something other than True, False, or None.
----------
assignee: rhettinger
components: Interpreter Core
messages: 141269
nosy: rhettinger
priority: low
severity: normal
status: open
title: Add __bool__ to None
versions: Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12647>
_______________________________________
More information about the Python-bugs-list
mailing list