Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python] Fix Cluster objects datatypes on Python 3.11 (#26729)
* [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. * [python] Mark Nullable type frozen * address linter error * Revert dataclass frozen * Add comment
- Loading branch information