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

Error with python3.11 #12

Open
martin3000 opened this issue May 26, 2023 · 2 comments
Open

Error with python3.11 #12

martin3000 opened this issue May 26, 2023 · 2 comments

Comments

@martin3000
Copy link

Running HA with python3.11, I get this error.
See https://docs.python.org/3.11/whatsnew/3.11.html#dataclasses
Maybe adding a __hash__ method will fix it.

2023-05-26 17:39:45.808 ERROR (MainThread) [homeassistant.loader] Unexpected exception importing platform custom_components.artnet_led.light
Traceback (most recent call last):
  File "/home/nuc/.local/lib/python3.11/site-packages/homeassistant/loader.py", line 833, in get_platform
    cache[full_name] = self._import_platform(platform_name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuc/.local/lib/python3.11/site-packages/homeassistant/loader.py", line 850, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/nuc/.homeassistant/custom_components/artnet_led/light.py", line 40, in <module>
    from custom_components.artnet_led.bridge.artnet_controller import ArtNetController
  File "/home/nuc/.homeassistant/custom_components/artnet_led/bridge/artnet_controller.py", line 11, in <module>
    from custom_components.artnet_led.client import PortAddress
  File "/home/nuc/.homeassistant/custom_components/artnet_led/client/__init__.py", line 240, in <module>
    @dataclass
     ^^^^^^^^^
  File "/usr/lib/python3.11/dataclasses.py", line 1221, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/usr/lib/python3.11/dataclasses.py", line 1211, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/dataclasses.py", line 959, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/dataclasses.py", line 816, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'custom_components.artnet_led.client.GoodInput'> for field good_input is not allowed: use default_factory
@martin3000
Copy link
Author

This hack fixed it for the moment. I added it to the classes GoodInput, GoodOutputA, Port and ArtIpProgCommand

    def __hash__(self):  # jms
        return hash(123456789)

    def __eq__(self, other):
        return (
            self.__class__ == other.__class__
        )

@Breina
Copy link
Contributor

Breina commented Jun 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