Closed dalmaer closed 1 year ago
Changed in version 3.11: Instead of looking for and disallowing objects of type list, dict, or set, unhashable objects are now not allowed as default values. Unhashability is used to approximate mutability.
https://docs.python.org/3/library/dataclasses.html#dataclasses.make_dataclass
so we can make it hashable via: def __hash__(self):...
and we are good? :)
Yeah, or create a helper function similar to empty()
that acts as default_factory
.
Instead of
restricted: RestrictedConfig = RestrictedConfig()
It will be something like
restricted: RestrictedConfig = empty(RestrictedConfig)
or maybe
restricted: RestrictedConfig = default(RestrictedConfig)
I was able to get passed that with some empty(FooConfig).
Now I'm getting:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/dionalmaer/Projects/polymath/host/server.py", line 10, in <module>
import polymath
File "/Users/dionalmaer/Projects/polymath/polymath/__init__.py", line 1, in <module>
from polymath.library import Library, Bit, CURRENT_VERSION, EMBEDDINGS_MODEL_ID
File "/Users/dionalmaer/Projects/polymath/polymath/library.py", line 14, in <module>
from .access import DEFAULT_PRIVATE_ACCESS_TAG, HOST_CONFIG, permitted_access
File "/Users/dionalmaer/Projects/polymath/polymath/access.py", line 6, in <module>
HOST_CONFIG = JSONConfigStore().load(HostConfig)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dionalmaer/Projects/polymath/polymath/config/json.py", line 33, in load
return config_type(config)
^^^^^^^^^^^^^^^^^^^
File "/Users/dionalmaer/Projects/polymath/polymath/base/dataclasses.py", line 114, in init
**build_config_kwards(cls, config_args))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dionalmaer/Projects/polymath/polymath/base/dataclasses.py", line 89, in build_config_kwards
config_kwargs[name] = field_type(value)
^^^^^^^^^^^^^^^^^
File "/Users/dionalmaer/Projects/polymath/polymath/base/dataclasses.py", line 114, in init
**build_config_kwards(cls, config_args))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dionalmaer/Projects/polymath/polymath/base/dataclasses.py", line 82, in build_config_kwards
if is_a_dataclass_dict(field_type) and value is not None:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dionalmaer/Projects/polymath/polymath/base/dataclasses.py", line 12, in is_a_dataclass_dict
is_a_dict_subclass = type is not dict and type.__subclasscheck__(dict)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/typing.py", line 1285, in __subclasscheck__
raise TypeError("Subscripted generics cannot be used with"
TypeError: Subscripted generics cannot be used with class and instance checks
The error message you're seeing suggests that you're trying to use subscripted generics (e.g., List[str]) with class and instance checks (e.g., isinstance(obj, List)).
To fix this, you can either use the subscripted version consistently or the non-subscripted version consistently, but don't mix them