Skip to content
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

4.2.0: Bitarray(bytes=...) constructor no longer accepts list of bytes (or integers) #318

Closed
EricGallimore opened this issue Apr 23, 2024 · 2 comments
Assignees
Milestone

Comments

@EricGallimore
Copy link

In version prior to 4.2.0, this works:

list_of_bytes = [0x01, 0x02]
bits = BitArray(bytes=list_of_bytes)

In 4.2.0, a TypeError is thrown. Example:

Traceback (most recent call last):
  File "/home/eric/ros_workspace/src/ros_acomms/ros_acomms/src/message_queue_node.py", line 796, in handle_get_next_packet
    messages_in_packet, miniframe_bytes, dataframe_bytes = packet_codec.encode_payload(num_miniframe_bytes,
  File "/home/eric/ros_workspace/src/ros_acomms/ros_acomms/src/acomms_codecs/ros_packet_codec.py", line 64, in encode_payload
    miniframe_bits = BitArray(bytes=self.miniframe_header)
  File "/home/eric/.local/lib/python3.8/site-packages/bitstring/bits.py", line 124, in __new__
    x._initialise(auto, length, offset, **kwargs)
  File "/home/eric/.local/lib/python3.8/site-packages/bitstring/bits.py", line 149, in _initialise
    self._setbytes_with_truncation(v, length, offset)
  File "/home/eric/.local/lib/python3.8/site-packages/bitstring/bits.py", line 622, in _setbytes_with_truncation
    return self._setbytes(data)
  File "/home/eric/.local/lib/python3.8/site-packages/bitstring/bits.py", line 616, in _setbytes
    self._bitstore = BitStore.frombytes(data)
  File "/home/eric/.local/lib/python3.8/site-packages/bitstring/bitstore.py", line 41, in frombytes
    x._bitarray.frombytes(b)
TypeError: a bytes-like object is required, not 'list'

(Converting the list of bytes/ints to bytes by calling bytes(list_of_bytes) fixes this, but this is still a change in 4.2.0 that breaks backward compatibility.)

scott-griffiths added a commit that referenced this issue Apr 23, 2024
…ctor. Bug #318.

Upping version to 4.2.1 for new release.
@scott-griffiths scott-griffiths self-assigned this Apr 23, 2024
@scott-griffiths scott-griffiths added this to the 4.2.1 milestone Apr 23, 2024
@scott-griffiths
Copy link
Owner

Hi. Thanks for the bug report.

You're right, that was an unintended side effect of some refactoring. I've fixed it and added a test.

Good timing - just in time for the 4.2.1 release! Thanks again.

@scott-griffiths
Copy link
Owner

This should be working again the 4.2.1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants