scott-griffiths/bitstring

4.2.0 crashes upon import when PYTHONOPTIMIZE is set to 2 or larger

ntamas opened this issue · 2 comments

ntamas commented

Steps to reproduce:

PYTHONOPTIMIZE=2 venv/bin/python3
Python 3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bitstring
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/venv/lib/python3.12/site-packages/bitstring/__init__.py", line 305, in <module>
    Bits.__doc__ = Bits.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
                   ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'replace'

This is because starting Pyhton with PYTHONOPTIMIZE=2 or with the -O0 argument strips away the docstrings so Bits.__doc__ becomes None.

Ah, that's not something I had considered!

I've reproduced it and will get a fix in for version 4.2.1 shortly.

Thank you for the bug report.

This should be working again the 4.2.1 release.