Skip to content

Error Importing Astromodels with python 3.11.3 #201

@parsotat

Description

@parsotat

I have upgraded to astromodels 2.4.0 and I am trying to import the module and get the following error:

ipython                          
Python 3.11.3 (main, Apr 19 2023, 18:51:09) [Clang 14.0.6 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from typing import Dict
   ...: 
   ...: import numpy as np
   ...: from astromodels import Band
   ...: import ronswanson as dukesilver
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], line 4
      1 from typing import Dict
      3 import numpy as np
----> 4 from astromodels import Band
      5 import ronswanson as dukesilver

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/astromodels/__init__.py:14
      7 # Import the version
      8 
      9 #
     10 #
     12 if os.environ.get("ASTROMODELS_DEBUG", None) is None:
---> 14     from .utils.configuration import astromodels_config
     15     from .core.memoization import use_astromodels_memoization
     16     from .core.model import Model

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/astromodels/utils/configuration.py:5
      1 from omegaconf import OmegaConf
      3 from astromodels.utils import get_path_of_user_config
----> 5 from .config_structure import Config
      7 # Read the default Config
      8 astromodels_config: Config = OmegaConf.structured(Config)

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/astromodels/utils/config_structure.py:69
     63     use_parameter_transforms: bool = True
     64     ignore_parameter_bounds: bool = False
---> 69 @dataclass
     70 class Config:
     71     logging: Logging = Logging()
     72     absorption_models: AbsorptionModels = AbsorptionModels()

File ~/opt/anaconda3/envs/py311/lib/python3.11/dataclasses.py:1223, in dataclass(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots, weakref_slot)
   1220     return wrap
   1222 # We're called as @dataclass without parens.
-> 1223 return wrap(cls)

File ~/opt/anaconda3/envs/py311/lib/python3.11/dataclasses.py:1213, in dataclass.<locals>.wrap(cls)
   1212 def wrap(cls):
-> 1213     return _process_class(cls, init, repr, eq, order, unsafe_hash,
   1214                           frozen, match_args, kw_only, slots,
   1215                           weakref_slot)

File ~/opt/anaconda3/envs/py311/lib/python3.11/dataclasses.py:958, in _process_class(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots, weakref_slot)
    955         kw_only = True
    956     else:
    957         # Otherwise it's a field of some type.
--> 958         cls_fields.append(_get_field(cls, name, type, kw_only))
    960 for f in cls_fields:
    961     fields[f.name] = f

File ~/opt/anaconda3/envs/py311/lib/python3.11/dataclasses.py:815, in _get_field(cls, a_name, a_type, default_kw_only)
    811 # For real fields, disallow mutable defaults.  Use unhashable as a proxy
    812 # indicator for mutability.  Read the __hash__ attribute from the class,
    813 # not the instance.
    814 if f._field_type is _FIELD and f.default.__class__.__hash__ is None:
--> 815     raise ValueError(f'mutable default {type(f.default)} for field '
    816                      f'{f.name} is not allowed: use default_factory')
    818 return f

ValueError: mutable default <class 'astromodels.utils.config_structure.Logging'> for field logging is not allowed: use default_factory

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions