CMakePP / CMinx

Generates API documentation for CMake functions and macros
https://cmakepp.github.io/CMinx/
Apache License 2.0
14 stars 5 forks source link

[Question] Getting the error `ValueError: mutable default <class 'cminx.config.InputSettings'> for field input is not allowed: use default_factory` #142

Closed dschiller closed 1 year ago

dschiller commented 1 year ago

Before opening this issue I:

When I execute cminx I get the following error:

cminx
Traceback (most recent call last):
  File "/Volumes/K2TB/Work/CMake/tools/develop/.venv/bin/cminx", line 5, in <module>
    from cminx import main
  File "/Volumes/K2TB/Work/CMake/tools/develop/.venv/lib/python3.11/site-packages/cminx/__init__.py", line 38, in <module>
    from .config import config_template, dict_to_settings, Settings
  File "/Volumes/K2TB/Work/CMake/tools/develop/.venv/lib/python3.11/site-packages/cminx/config.py", line 101, in <module>
    @dataclass
     ^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.2/Frameworks/Python.framework/Versions/3.11/lib/python3.11/dataclasses.py", line 1220, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.2/Frameworks/Python.framework/Versions/3.11/lib/python3.11/dataclasses.py", line 1210, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.2/Frameworks/Python.framework/Versions/3.11/lib/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.2/Frameworks/Python.framework/Versions/3.11/lib/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'cminx.config.InputSettings'> for field input is not allowed: use default_factory
CMinx==1.1.0
Python 3.11.2
dschiller commented 1 year ago

With Python 3.8.2 it works.

ryanmrichard commented 1 year ago

I'm going to reopen this issue, but specify the issue as ensure CMinx works with Python 3.11 (we currently test with up to 3.10). Hopefully that takes care of the issue @dschiller saw too.

AutonomicPerfectionist commented 1 year ago

It appears restrictions on dataclass defaults mutability were tightened in 3.11, should be a very simple change to fix. I'll also try to get testing with 3.11 working as well