But when I do this bitwise.py croaks with "bit array must be divisible by 8." (trace below).
Why is it this way? The second form would be much simpler and cleaner overall in the code to work with.
Because everything is bytes underneath? I'm not sure how to explain it, but if you look at bitwise, everything has to map to a byte and an offset at some point. The bit array maps to a whole byte, which is why it has to be eight elements long.
Is there some alignment concern? Is there any provision for a data type of less than a byte?
It gets really complicated if you try to support something like this (which is equivalent to what you're asking for):
struct { bit a; u8 b; bit c; u24 d; } foo;
In the above, b is eight bits that span a byte. c is in the third byte and d ends in the seventh byte with some bits left over. Implementation complexity aside, supporting the above also means it becomes very difficult to realize that there are some unaddressed bits left over at the end of foo, and it's difficult to know the address where the thing that comes after foo starts, especially if you think you've created something that is a whole number of bytes.
So, complexity of supporting the unaligned accesses, and the complexity of validating something by looking at it led me to write it such that everything had to be aligned to byte boundaries. For most cases, this is really not a problem, and I don't think the few cases that suffer are worth the additional complexity. It's pretty easy to just define a few helper methods to make things easier to understand, IMHO.
--Dan