You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Attempting to use gridapps.simulation with python 3.11 will result in ValueError due to Python 3.11 changing dataclass to be non-backwards compatible (see i.e. this discussion).
The ValueError is due to SimulationArgs, SimulationConfig, having class defaults (ModelCreationConfig and SimulationArgs, ApplicationConfig, TestConfig, respectively).
To Reproduce
$ mkdir tmp &&cd tmp
$ py --version
Python 3.11.4
$ py -m venv .
$ py -m pip install gridappsd-python
$ py
>>> import gridappsd.simulation
Traceback (most recent call last):
File "<stdin>", line 1, in<module>
File "C:\Users\danielbje\tmp\Lib\site-packages\gridappsd\simulation.py", line 51, in<module>
@dataclass
^^^^^^^^^
File "C:\Users\danielbje\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 1230, in dataclass
return wrap(cls)
^^^^^^^^^
File "C:\Users\danielbje\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 1220, in wrap
return _process_class(cls, init, repr, eq, order, unsafe_hash,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\danielbje\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 958, in _process_class
cls_fields.append(_get_field(cls, name, type, kw_only))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\danielbje\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 815, in _get_field
raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'gridappsd.simulation.ModelCreationConfig'>for field model_creation_config is not allowed: use default_factory
Proposed solution
Use default_factory for these fields as well.
I can confirm this issue with python greater than 3.10. The suggested solution is will work however, i believe this would work as well:
field(default_factory=ModelCreationConfig)
field(default_factory=SimulationArgs)
field(default_factory=ApplicationConfig)
field(default_factory=TestConfig)
Describe the bug
Attempting to use gridapps.simulation with python 3.11 will result in ValueError due to Python 3.11 changing dataclass to be non-backwards compatible (see i.e. this discussion).
The ValueError is due to SimulationArgs, SimulationConfig, having class defaults (ModelCreationConfig and SimulationArgs, ApplicationConfig, TestConfig, respectively).
To Reproduce
Proposed solution
Use default_factory for these fields as well.
and
Elsewise, README and pyproject-dotfiles should be changed to reflect <3.11 requirement.
See also this issue for inspiration
The text was updated successfully, but these errors were encountered: