scott-griffiths / bitstring

A Python module to help you manage your bits
https://bitstring.readthedocs.io/en/stable/index.html
MIT License
401 stars 67 forks source link

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

Closed ntamas closed 3 months ago

ntamas commented 3 months ago

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.

scott-griffiths commented 3 months ago

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.

scott-griffiths commented 3 months ago

This should be working again the 4.2.1 release.