[Python-Dev] Boolean transition (original) (raw)

Guido van Rossum guido@python.org
Sun, 10 Mar 2002 20:21:35 -0500


[PP]

If you're arguing that booleans should be subtypes of integers because integers can be used in a boolean context then I guess booleans should ALSO be subtypes of strings and lists because strings and lists can also be used in a boolean fashion.

I don't know about others, but my arguments for making bool a subtype of int has nothing to do with the fact that ints can be used in a bool context. (That would be reversing the inheritance, as you point out.) It is rather the opposite: bool values gotten from certain operations (e.g. comparisons, and most built-in predicate functions) are commonly used in int contexts, because they are currently represented by 0 and 1. So the constraint under which we're operating is that bool values must be ints. This constraint has only two possible solutions: (a) continue to use int as the type of choice for bool results, and define builtins False = 0 and True = 1; or (b) make bool a subtype of int.

I do not want to say that in the future only bool is acceptable in a Boolean context; it would remove too many of my favorite ways of expression things clearly with few words. That's my final word on this particular subissue.

--Guido van Rossum (home page: http://www.python.org/~guido/)