[Python-Dev] bool conversion wart? (original) (raw)
Mike Klaas mike.klaas at gmail.com
Fri Feb 23 02:56:47 CET 2007
- Previous message: [Python-Dev] bool conversion wart?
- Next message: [Python-Dev] bool conversion wart?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] bool conversion wart?
- Next message: [Python-Dev] bool conversion wart?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]