[Python-Dev] bool conversion wart?

Georg Brandl g.brandl at gmx.net
Sat Feb 24 19:42:41 CET 2007


Guido van Rossum schrieb:
> Can anyone who is in favor of changing this please come up with a spec
> for the new bool() signature? What would you do for the most common
> use case of bool(), which is converting an arbitrary value to its
> Boolean equivalent without using an if test or the "not not x" hack?

I think this subthread doesn't propose to change bool(), but only to
stop inheriting bool from int, while giving bools an __index__ method
that returns 0 or 1 to still allow them being used as list indices.

The obvious consequence would be that arithmetic wouldn't work any
longer with bools involved.

Also, mapping access or set membership wouldn't work like now,

 >>> d = {1: 2}
 >>> d[True]
2
 >>> True in set([1])
True

but that would only be logical.

Georg



More information about the Python-Dev mailing list