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.join() no longer ignores None types #323

Closed
Algafix opened this issue Apr 25, 2024 · 2 comments
Closed

4.2.0: BitArray.join() no longer ignores None types #323

Algafix opened this issue Apr 25, 2024 · 2 comments

Comments

@Algafix
Copy link

Algafix commented Apr 25, 2024

Hello!

Thanks for the amazing library and for the continuous improvements, it is really helpful!

I've noticed that, since the 4.2.0 update, there is a behavioral change that breaks backward compatibility and is not reported in the version notes.

Previous to 4.2.0, when joining a list of BitArrays the None items were ignored, but now it tries to initialise them and raises an error.

l = [BitArray('0x2'), None, BitArray('0x3')]
BitArray().join(l)

bitstring == 4.1.4

BitArray('0x23')

bitstring == 4.2.1

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/python3.8/site-packages/bitstring/bits.py", line 1479, in join
    s._addright(Bits._create_from_bitstype(item))
  File "/lib/python3.8/site-packages/bitstring/bits.py", line 132, in _create_from_bitstype
    b._setauto_no_length_or_offset(auto)
  File "/lib/python3.8/site-packages/bitstring/bits.py", line 518, in _setauto_no_length_or_offset
    raise TypeError(f"Cannot initialise bitstring from type '{type(s)}'.")
TypeError: Cannot initialise bitstring from type '<class 'NoneType'>'.

Thank you a lot!

@scott-griffiths
Copy link
Owner

Hi, thanks for the bug report.

I'll take a look at what's caused the change to see how intentional this change was. It's possible it's a side-effect of a good change that wasn't noticed or documented. If so I'd be tempted to call it an undocumented bug fix.

I'm not sure, but the TypeError trying to initialise a bitstring from None does feel like the right behaviour. If you have a good use case for needed to initialise from None then I'd be interested to see it.

Either way it's an undocumented change, so thanks for letting me know. I'll either fix it or document it as intentional in the next point release.

@scott-griffiths scott-griffiths self-assigned this Apr 25, 2024
@scott-griffiths scott-griffiths added this to the 4.2.2 milestone Apr 25, 2024
@Algafix
Copy link
Author

Algafix commented Apr 26, 2024

For me, the current behavior makes more sense :)

Thanks!

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