-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constructor fed with iterable bytes starting with a leading 0x00-0x07 silently treats the bytes as a python pickle... #206
Comments
Thank you for using bitarray and filing this issue! The described behavior is correct, i.e. then a bitarray is initialized with bytes and the leading one is the range 0x00 to 0x07, then the remaining bytes are treated as the raw buffer (with the leading byte indicating how many unused bits are present). What would you suggest to fix this issue? Change the documentation? |
Hi, another example of how this can surprise:
I don't really wish to weigh in on what should be happening, but I don't think that documenting it is the answer. I'm not very familiar with pickle, but I thought you could avoid using |
@scott-griffiths I agree that it would be best to avoid
I will try to use this approach in bitarray as well, while keeping things backwards compatible. |
@scott-griffiths I just created #207, which uses a reconstructor function and also explains the history and technical details. TL;DR: To allow a backwards compatibility transition, this issue (#206) can be closed a year from now! |
The documentation of the
bitarray
class claims that the initializer can be:Since
bytes
are iterable, it is natural to assume that providingbytes
as an initializer will be equivalent to a.frombytes()
call... However, it appears that if the leading byte is in the range '0x00' through '0x07', the initializer is assumed to be a python pickle. The difference is counter-intuitive and confusing since a call fed from a binary file with a leading0x00
will yield an almost "equivalent" bitarray with exactly one byte missing... Which can be hard to spot :-)These are even more counter-intuitive:
The text was updated successfully, but these errors were encountered: