[Python-Dev] PEP 285: Adding a bool type (original) (raw)

David Abrahams David Abrahams" <david.abrahams@rcn.com
Sat, 30 Mar 2002 09:04:31 -0500


----- Original Message ----- From: "Guido van Rossum" <guido@python.org> To: "David Abrahams" <david.abrahams@rcn.com> Cc: <python-list@python.org>; <python-dev@python.org> Sent: Saturday, March 30, 2002 8:47 AM Subject: Re: [Python-Dev] PEP 285: Adding a bool type

[David Abrahams] > 6) Should we eventually remove the inheritance relationship > between Int and Bool? > > I hope so. Bool is-a Int doesn't seem like the right relationship to > me, unless perhaps we make Int is-a Long... naah, not even then.

Hm. In your favorite language bool is one of the integral types. Doesn't that imply pretty much the same thing?

Well, I try not to play favorites <0.002 wink>, but the implicit conversion rules in C++ are admittedly and unfortunately liberal. However, bool is detectably NOT derived from int in C++:

void f(int const&);
f(false); // error!
assert(boost::is_base_and_derived<int,bool>::value); // fails!

Anyway, do you have a use case where it matters?

Given that Bool is immutable, I have no cases other than examples of type introspection which can be written to account for the fact that Bool is-a Int. However, it does make certain things trickier to get right:

numeric_types = [ Int, Long, Bool, Float, Complex ] for t in numeric_types: if isinstance(x, t): # Do something...

This sort of thing could depend on getting the order of the list right (I didn't).

-Dave