This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients jcea, mark.dickinson, terry.reedy
Date 2013-02-09.01:58:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1360375098.97.0.437781149387.issue17152@psf.upfronthosting.co.za>
In-reply-to
Content
You are proposing a bit array. Whether the bits are interpreted or displayed as 0/1 or f/t or False/True is secondary. The problem is that bit arrays do not fit the array model, with its minimum byte size per element of 1. There are other aspects of arrays that do not fit either. What would .itemsize() return? fractions. Fraction(1,8)? In any case, the internal implementation will be substantially different.

So I suggest that the proposal be to add an array.bitarray class. The bit representation strings '0'/'1', 'f'/'t', 'False'/'True' could be parameters. Omit typecode, typecodes, amd itemsize attributes and byteswap and (to or from)string methods. The buffer_info method would need redefinition. Should (to/from)(bytes/file) use 1 byte per bit (is so, which ones) or pack 8 bits per byte? It would be sensible to add bitwise operators (~, &, |, ^) on bit arrays of the same length. An implementation decision is the granularity of the internal storage (1, 2, 4, or possibly 8 bytes on 64 bit systems -- or just use 3.x ints).  The insert/delete methods might be omitted, but implementation of such should be similar to the shift methods for integers, which have the same problem of moving bits between internal implementation chunks.

I suspect that many have implemented versions of this in Python (as well as other languages) using bytes or ints with masks. I suggest you present the idea on python-ideas list to garner more support -- and be prepred to write a PEP for a new class.

I suspect that the relative ease of using ints as bit arrays will be an argument against such an addition. That is why they have the bit operations. On the other hand, one might argue that the inclusion of bit operations acknowledges the need for bit arrays.
History
Date User Action Args
2013-02-09 01:58:19terry.reedysetrecipients: + terry.reedy, jcea, mark.dickinson
2013-02-09 01:58:18terry.reedysetmessageid: <1360375098.97.0.437781149387.issue17152@psf.upfronthosting.co.za>
2013-02-09 01:58:18terry.reedylinkissue17152 messages
2013-02-09 01:58:18terry.reedycreate