-
Notifications
You must be signed in to change notification settings - Fork 200
Avoid frozendict.deepfreeze
#1646
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
Conversation
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.
Pull Request Overview
This PR removes the problematic use of frozendict.deepfreeze which incorrectly converts primitive type subclasses to empty frozendicts by assuming that hashable equals immutable. The change replaces deepfreeze with a custom converter that properly handles nested dictionary structures while avoiding the flawed conversion behavior.
- Removes
frozendict.deepfreezeimport and usage - Replaces
deepfreezeconverter with a custom lambda that correctly handles nested dictionaries - Updates test values to use proper cluster ID references instead of hardcoded integers
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| zigpy/quirks/v2/init.py | Removes deepfreeze import and replaces its usage with a custom converter for nested frozendict creation |
| tests/test_quirks_v2.py | Updates test automation triggers to use cluster ID constants and adds assertion to verify correct cluster ID value |
| ] = attrs.field(factory=frozendict, converter=deepfreeze) | ||
| ] = attrs.field( | ||
| factory=frozendict, | ||
| converter=lambda d: frozendict({k: frozendict(v) for k, v in d.items()}), |
Copilot
AI
Aug 11, 2025
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.
The lambda converter assumes d is always a dictionary with the items() method. If d is not a dictionary or is None, this will raise an AttributeError. Consider adding type checking or using a proper function with error handling.
| converter=lambda d: frozendict({k: frozendict(v) for k, v in d.items()}), | |
| converter=_convert_device_automation_triggers_metadata, |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1646 +/- ##
=======================================
Coverage 99.29% 99.29%
=======================================
Files 57 57
Lines 11638 11638
=======================================
Hits 11556 11556
Misses 82 82 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| ] = attrs.field(factory=frozendict, converter=deepfreeze) | ||
| ] = attrs.field( | ||
| factory=frozendict, | ||
| converter=lambda d: frozendict({k: frozendict(v) for k, v in d.items()}), |
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 change already causes the TypeError: unhashable type: 'dict' in the one quirks test @puddly. I've only been looking at all the translation placeholder changes this whole time and was wondering why it didn't work 😅
Seen here: zigpy/zha-device-handlers#4251
This function makes a pretty bizarre assumption:
This fails for basically every primitive type subclass: