Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing import with py311 #19

Closed
gituser768 opened this issue Apr 28, 2023 · 1 comment
Closed

Failing import with py311 #19

gituser768 opened this issue Apr 28, 2023 · 1 comment

Comments

@gituser768
Copy link

python -c 'import springs' throws an error with python 3.11:

File ~/miniconda3/envs/term_extractor/lib/python3.11/site-packages/springs/__init__.py:5
      1 from dataclasses import dataclass
      3 from omegaconf import MISSING, SI, DictConfig, ListConfig
----> 5 from .commandline import cli
      6 from .core import (
      7     DEFAULT,
      8     cast,
   (...)
     24     validate,
     25 )
     26 from .field_utils import field

File ~/miniconda3/envs/term_extractor/lib/python3.11/site-packages/springs/commandline.py:96
     92     def __str__(self) -> str:
     93         return f"{self.short}/{self.long}"
---> 96 @dataclass
     97 class CliFlags:
     98     config: Flag = Flag(
     99         name="config",
    100         help=(
   (...)
    108         metavar="/path/to/config.yaml",
    109     )
    110     options: Flag = Flag(
    111         name="options",
    112         help="print all default options and CLI flags.",
    113         action="store_true",
    114     )

File ~/miniconda3/envs/term_extractor/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 ~/miniconda3/envs/term_extractor/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 ~/miniconda3/envs/term_extractor/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 ~/miniconda3/envs/term_extractor/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 'springs.commandline.Flag'> for field config is not allowed: use default_factory

To reproduce:

conda create --name reproduce_sp_bug python=3.11 pip
conda activate reproduce_sp_bug
pip install springs
python -c 'import springs'
@soldni
Copy link
Owner

soldni commented Aug 2, 2023

Fixed in #22! Springs is now compatible with Python 3.11.

@soldni soldni closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants