Comparisons and sorting of a numeric class....

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Jan 16 04:23:35 EST 2015


Ian Kelly wrote:
> Wait, are you actually asking why bool is a doubleton? If nobody has
> answered that, I think probably nobody understood you were asking it,
> because it shouldn't need to be explained.

What does perhaps need explaining is why Python goes
out of its way to *enforce* the doubleton-ness of bool.

I don't know all of Guido's reasoning on this, but part
of it is probably to do with implementation efficiencies.
There are several places in the CPython source where it's
assumed that, if an object is known to be of type bool,
then its truth or falseness can be determined with a
pointer comparison.

-- 
Greg



More information about the Python-list mailing list