Skip to content

Error Importing Astromodels with python 3.11.3 #201

Closed

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

Activity

  1. natj commented on Oct 11, 2023

    @natj

    same error here

  2. israelmcmc commented on Jun 6, 2024

    @israelmcmc
    Contributor

    I no longer see this issue using the master branch (d5c5416) and a fresh conda Python 3.11.3 installation.

    I'm not sure if it is related, but a new setuptools version was released recently. I had to use --use-pip517, as explained on #209. That's the only difference I can think of, I do remember being able to reproduce this issue before.

  3. israelmcmc commented on Jun 24, 2024

    @israelmcmc
    Contributor

    Digging a little more into this, I think @grburgess addressed this issue specifically in commit 8f4610d. This commit made to the latest release 2.4.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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