mhostetter / galois

A performant NumPy extension for Galois fields and their applications
https://mhostetter.github.io/galois/
MIT License
295 stars 27 forks source link

Support running with CPython's -OO flag #544

Closed jcharlong closed 4 weeks ago

jcharlong commented 1 month ago

Hello, I run my application with CPython & utilize its -OO flag which remove docstrings. I run into the following error when doing so with galois:

File "/tmp/.mount_hl1500PdhjIa/usr/lib/python3.12/site-packages/galois/__init__.py", line 24, in <module>
  from ._fields import *
File "/tmp/.mount_hl1500PdhjIa/usr/lib/python3.12/site-packages/galois/_fields/__init__.py", line 4, in <module>
  from ._array import *
File "/tmp/.mount_hl1500PdhjIa/usr/lib/python3.12/site-packages/galois/_fields/_array.py", line 25, in <module>
  class FieldArray(Array, metaclass=FieldArrayMeta):
File "/tmp/.mount_hl1500PdhjIa/usr/lib/python3.12/site-packages/galois/_fields/_array.py", line 214, in FieldArray
  @extend_docstring(
  ^^^^^^^^^^^^^^^^^
File "/tmp/.mount_hl1500PdhjIa/usr/lib/python3.12/site-packages/galois/_helper.py", line 112, in decorator
  parent_docstring = parent_docstring.replace(from_str, to_str)
                   ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'replace'

I believe the getattr call with a default empty string does not work here since CPython is replacing existing docstrings with None.

I will create a PR to resolve this issue and handle the None docstring case shortly.

mhostetter commented 4 weeks ago

Thanks for this addition. Released in v0.3.9.