-
Notifications
You must be signed in to change notification settings - Fork 75
fix: ensure keys are correct type when serializing from data #630
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,8 +67,8 @@ def _convert_to_class_obj(class_type: type, value): | |
| sub_type = get_args(class_type)[0] | ||
| return [RoborockBase._convert_to_class_obj(sub_type, obj) for obj in value] | ||
| if get_origin(class_type) is dict: | ||
| _, value_type = get_args(class_type) # assume keys are only basic types | ||
| return {k: RoborockBase._convert_to_class_obj(value_type, v) for k, v in value.items()} | ||
| key_type, value_type = get_args(class_type) | ||
| return {key_type(k): RoborockBase._convert_to_class_obj(value_type, v) for k, v in value.items()} | ||
|
||
| if inspect.isclass(class_type): | ||
| if issubclass(class_type, RoborockBase): | ||
| return class_type.from_dict(value) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unpacking will fail with a
ValueError: not enough values to unpackwhen encountering untypeddictfields (e.g.,device_status: dict | Noneat line 242 in this file). For untyped dicts,get_args(dict)returns an empty tuple().Consider adding a check for this case: