Skip to content

Commit 3d2ccb1

Browse files
Fix for crash when docstrings are optimized out. Bug scott-griffiths#321.
1 parent 96c2103 commit 3d2ccb1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

bitstring/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,15 @@ def bool_bits2chars(bitlength: Literal[1]):
302302
property_docstrings = [f'{name} -- Interpret as {dtype_register[name].description}.' for name in dtype_register.names]
303303
property_docstring = '\n '.join(property_docstrings)
304304

305-
Bits.__doc__ = Bits.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
306-
BitArray.__doc__ = BitArray.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
307-
ConstBitStream.__doc__ = ConstBitStream.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
308-
BitStream.__doc__ = BitStream.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
305+
# We can't be sure the docstrings are present, as it might be compiled without docstrings.
306+
if Bits.__doc__ is not None:
307+
Bits.__doc__ = Bits.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
308+
if BitArray.__doc__ is not None:
309+
BitArray.__doc__ = BitArray.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
310+
if ConstBitStream.__doc__ is not None:
311+
ConstBitStream.__doc__ = ConstBitStream.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
312+
if BitStream.__doc__ is not None:
313+
BitStream.__doc__ = BitStream.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
309314

310315

311316
__all__ = ['ConstBitStream', 'BitStream', 'BitArray', 'Array',

0 commit comments

Comments
 (0)