[Python-Dev] bool conversion wart?

Mike Klaas mike.klaas at gmail.com
Fri Feb 23 02:56:47 CET 2007


On 2/22/07, Neal Becker <ndbecker2 at gmail.com> wrote:

> Except, all the numeric types do, including int, float, and complex.  But
> not bool.

Oh?

In [5]: str(complex(1, 2))
Out[5]: '(1+2j)'

In [6]: complex(str(complex(1, 2)))
---------------------------------------------------------------------------
<type 'exceptions.ValueError'>: complex() arg is a malformed string


> In fact, this is not just academic.  The fact that other numeric
> types act this way leaves a reasonable expectation that bool will.
> Instead, bool fails in _the worst possible way_: it silently gives a _wrong
> result_.

I'd debate the assertion that 'bool' is a numeric type (despite being
a subclass of int).

For bool() to return anything other than the value of the python
expression evaluated in boolean context would be _lunacy_ and there is
absolutely no chance it that will be changed.

-Mike


More information about the Python-Dev mailing list