MiniChain icon indicating copy to clipboard operation
MiniChain copied to clipboard

Python 3.11 data class error

Open mattf1n opened this issue 1 year ago • 0 comments

When using Python 3.11 importing MiniChain causes an error.

mfinlayson  ~/MiniChain $  python -c "import minichain"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/mfinlayson/MiniChain/minichain/__init__.py", line 1, in <module>
    from .backend import (
  File "/Users/mfinlayson/MiniChain/minichain/backend.py", line 309, in <module>
    @dataclass
     ^^^^^^^^^
  File "/Users/mfinlayson/.pyenv/versions/3.11.9/lib/python3.11/dataclasses.py", line 1232, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/Users/mfinlayson/.pyenv/versions/3.11.9/lib/python3.11/dataclasses.py", line 1222, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mfinlayson/.pyenv/versions/3.11.9/lib/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mfinlayson/.pyenv/versions/3.11.9/lib/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'minichain.backend.RunLog'> for field run_log is not allowed: use default_factory

This can be fixed by changing RunLog() to field(default_factory=RunLog) in backends.py, though I'm not sure if this would introduce other bugs.

mattf1n avatar Jul 09 '24 18:07 mattf1n