[Python-Dev] Bool type and arrays (original) (raw)

Guido van Rossum guido@python.org
Fri, 08 Mar 2002 13:32:11 -0500


Guido said not to "mix up" the question of bit arrays with the bool proposal, but really, they are mixed up. The minute there is a bool type in Python people will be able to make Numeric arrays (not to mention Python arrays) with elements of type "bool".

I dunno about Numeric, but you cannot use an arbitrary type for the 'array' module -- you must use one of the documented codes that tell the array module what size items to use. Since there's no code (documented or otherwise) that refers to bool, you won't be able to create bool arrays with the array module.

I thought Numeric used a similar scheme?

They will then be annoyed to learn that they are making arrays of objects and the result is a big array, not a small array, and that they would have been better off with our byte integer arrays. Depending on the implementation, mixing in bool values in a list of integers might persuade Numeric's array constructor to make them all objects.

I made bool a subclass of int to minimize this danger, but I don't know whether Numeric uses PyInt_Check() or not. If it uses that macro, it should be safe.

In short, they are mixed up in the sense that this proposed intellectual nicety will cause us Nummies a lot of grief. Not that you aren't allowed to give us grief, like you did with the "true division", but I wanted people to know they would be inflicting pain.

But let's not worry about pain we don't know that we'll really be experiencing. I like to look at things from the bright side.

Wait until I check it into CVS next week. :-)

BTW: There is quite a bit of pent-up demand in the Numeric community for bit arrays. However, nobody knows how to do it since the internal Numpy structures use a byte as the atomic unit of addressing.

Same for the Python array module.

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