bool behavior in Python 3000?
Steven Bethard
steven.bethard at gmail.com
Wed Jul 11 09:14:53 EDT 2007
Steven D'Aprano wrote:
> On Tue, 10 Jul 2007 17:47:47 -0600, Steven Bethard wrote:
>> But I think all you're really saying is that newbies don't expect things
>> like +, -, *, etc. to work with bools at all. Which I agree is probably
>> true.
>
> No, what I am saying is that True and False being integers under the hood
> is a surprising implementation detail. It has no _inherent_ benefit: it
> is merely a practical way to bring bools into the language while
> remaining backward compatible. For Python 2.x, that was the least bad
> solution to the issue "oops, we should have included a bool type".
>
> Python 3 is allowed to break backwards compatibility, and there is no
> reason I can see to keep the current hack.
Remember that while Python 3 is allowed to break backwards
compatibility, it's only supposed to do it when there are concrete
benefits. Clearly there are existing use cases for treating bools like
ints, e.g. from Alexander Schmolck's email:
(x < b) * f(x)
-1 ** (i == j)
If you want to remove this functionality, you're going to need to
provide some new use cases that it satisfies that are clearly more
important than these existing ones.
STeVe
More information about the Python-list
mailing list