-
Notifications
You must be signed in to change notification settings - Fork 9
Avoid None-init for smile_version #699
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
WalkthroughThe pull request introduces changes across multiple files in the Plugwise library, focusing on modifying the handling of Changes
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #699 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 21 21
Lines 3408 3408
=========================================
Hits 3408 3408 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
plugwise/helper.py (1)
789-789
: Consider using a more explicit sentinel value.Using
Version("0.0.0")
as a sentinel value to check version initialization is not immediately clear in its intent. Consider:
- Using a named constant to clarify the intent
- Adding a comment explaining why this specific version is used as a sentinel
+# Sentinel value indicating uninitialized version +UNINITIALIZED_VERSION = version.Version("0.0.0") + def _control_state(self, data: GwEntityData, loc_id: str) -> str | bool: # ... - if self.smile_version != version.Version("0.0.0"): + if self.smile_version != UNINITIALIZED_VERSION:
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
plugwise/__init__.py
(2 hunks)plugwise/helper.py
(2 hunks)plugwise/legacy/helper.py
(1 hunks)plugwise/legacy/smile.py
(1 hunks)plugwise/smile.py
(1 hunks)
🔇 Additional comments (6)
plugwise/legacy/smile.py (1)
53-53
: LGTM! Type enforcement improvement for smile_version.The change from
Version | None
toVersion
enforces that a valid version object must be provided, which aligns with how the parameter is used in the class. This improves type safety and makes version handling more consistent across the codebase.plugwise/legacy/helper.py (1)
75-75
: LGTM! Improved type safety for smile_version attribute.The change from
Version | None
toVersion
better reflects the actual usage of the attribute in the code, particularly in the_create_legacy_gateway
method where it's always expected to have a value.plugwise/__init__.py (2)
83-83
: LGTM! Safe default initialization for smile_version.Initializing with
Version("0.0.0")
provides a safe default value instead of None, which is better aligned with how the version is used in version comparison checks throughout the code.
118-118
: LGTM! Improved return type consistency in connect method.The return type change from
Version | None
toVersion
accurately reflects that the method always returns a valid version through the_smile_detect
call, making the API contract clearer.plugwise/smile.py (1)
62-62
: LGTM! Type enforcement improvement for smile_version.The change from
Version | None
toVersion
enforces that a valid version object must be provided, which aligns with how the parameter is used in the class and stored in the instance attribute.plugwise/helper.py (1)
89-89
: Verify all initialization paths for smile_version.The type change from nullable to non-nullable requires that
smile_version
always contains a validVersion
object. Please ensure that all code paths properly initialize this attribute.Run the following script to verify the initialization:
✅ Verification successful
Type change for smile_version is properly initialized
All initialization paths for
smile_version
properly set a valid Version object through either constructor parameters or XML parsing. The change from nullable to non-nullable type is safe.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check all assignments to smile_version to ensure proper initialization # Search for direct assignments to smile_version rg -A 5 'self\.smile_version\s*=' # Search for class constructor and connect method implementations ast-grep --pattern 'def __init__($$$) { $$$ }' ast-grep --pattern 'def connect($$$) { $$$ }'Length of output: 2389
|
Suggestion by Coderabbitai from the last P: init
self.smile_name
other thanNone
.Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
smile_version
to always require a valid Version objectChores