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

[python] Fix Cluster objects datatypes on Python 3.11 #26729

Commits on May 22, 2023

  1. [python] Fix Cluster objects datatypes on Python 3.11

    It seems that Python 3.11 requires the custom data type Nullable to
    implement the __hash__() function, otherwise initializing dataclass
    annotated objects fail with the following stack trace:
    
    ```
      File "/home/sag/projects/project-chip/connectedhomeip-v1.1/.environment/pigweed-venv/lib/python3.11/site-packages/chip/clusters/Objects.py", line 385, in Commands
        @DataClass
         ^^^^^^^^^
      File "/usr/lib/python3.11/dataclasses.py", line 1223, in dataclass
        return wrap(cls)
               ^^^^^^^^^
      File "/usr/lib/python3.11/dataclasses.py", line 1213, in wrap
        return _process_class(cls, init, repr, eq, order, unsafe_hash,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/dataclasses.py", line 958, in _process_class
        cls_fields.append(_get_field(cls, name, type, kw_only))
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/dataclasses.py", line 815, in _get_field
        raise ValueError(f'mutable default {type(f.default)} for field '
    ValueError: mutable default <class 'chip.clusters.Types.Nullable'> for field capacity is not allowed: use default_factory
    ```
    
    Since all instances of Nullable are the same "value", we can return a
    static 0 as hash value.
    agners committed May 22, 2023
    Configuration menu
    Copy the full SHA
    98b431d View commit details
    Browse the repository at this point in the history

Commits on May 23, 2023

  1. Configuration menu
    Copy the full SHA
    51c51f2 View commit details
    Browse the repository at this point in the history
  2. address linter error

    agners committed May 23, 2023
    Configuration menu
    Copy the full SHA
    ac771d2 View commit details
    Browse the repository at this point in the history

Commits on May 24, 2023

  1. Revert dataclass frozen

    agners committed May 24, 2023
    Configuration menu
    Copy the full SHA
    97ddc5d View commit details
    Browse the repository at this point in the history
  2. Add comment

    agners committed May 24, 2023
    Configuration menu
    Copy the full SHA
    2092d50 View commit details
    Browse the repository at this point in the history