-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[python] Fix Cluster objects datatypes on Python 3.11 #26729
Conversation
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.
PR #26729: Size comparison from cbd5dac to 98b431d Increases (10 builds for bl702, cc32xx, cyw30739, esp32, k32w, nrfconnect, telink)
Decreases (12 builds for bl602, bl702, efr32, esp32, psoc6, telink)
Full report (57 builds for bl602, bl702, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
|
PR #26729: Size comparison from cbd5dac to 51c51f2 Increases (10 builds for cyw30739, esp32, k32w, nrfconnect, psoc6, telink)
Decreases (15 builds for bl602, bl702, cc32xx, efr32, k32w, nrfconnect, psoc6, telink)
Full report (57 builds for bl602, bl702, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
|
PR #26729: Size comparison from cbd5dac to 03ff7ce Increases (1 build for nrfconnect)
Full report (4 builds for mbed, nrfconnect)
|
03ff7ce
to
ac771d2
Compare
PR #26729: Size comparison from d1d37ec to ac771d2 Increases (3 builds for nrfconnect, telink)
Decreases (14 builds for bl602, bl702, efr32, psoc6, telink)
Full report (57 builds for bl602, bl702, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
|
@bzbarsky-apple do you happen to know if the test errors are related to this change or are those general errors we are seeing? It feels that this change could be at fault, but before diving into it, I'd rather ask.
|
@agners I have never seen that failure before, so there is a good chance it's due to this change... |
It seems that adding the annotation |
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:Since all instances of Nullable are the same "value", we can return a static 0 as hash value.