Skip to content

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

Merged
merged 4 commits into from
Jan 31, 2025
Merged

Avoid None-init for smile_version #699

merged 4 commits into from
Jan 31, 2025

Conversation

bouwew
Copy link
Contributor

@bouwew bouwew commented Jan 30, 2025

Suggestion by Coderabbitai from the last P: init self.smile_name other than None.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • No new user-facing features added
  • Bug Fixes

    • Improved version handling across multiple Plugwise library components
    • Ensured consistent version initialization and type safety
  • Refactor

    • Updated type declarations for smile_version to always require a valid Version object
    • Removed nullable version parameters in multiple classes
    • Standardized version initialization with a default "0.0.0" value
  • Chores

    • Enhanced type safety and code consistency in the Plugwise library
    • Added a new "Ongoing" section to the changelog highlighting improvements in version handling

Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

Walkthrough

The pull request introduces changes across multiple files in the Plugwise library, focusing on modifying the handling of smile_version attributes. The primary modification involves changing type declarations from nullable (Version | None) to non-nullable (Version) in various classes. This includes updates to the Smile, SmileHelper, SmileLegacyHelper, SmileLegacyAPI, and SmileAPI classes. The changes enforce stricter type requirements, ensuring that version-related attributes always contain a valid Version object.

Changes

File Change Summary
plugwise/__init__.py - Updated smile_version initialization to Version("0.0.0")
- Modified connect() method return type from `Version
plugwise/helper.py - Changed smile_version type from nullable to non-nullable
- Updated version check in _control_state method
plugwise/legacy/helper.py - Modified smile_version attribute to be non-nullable
plugwise/legacy/smile.py - Updated SmileLegacyAPI constructor to require Version parameter
plugwise/smile.py - Changed SmileAPI constructor to require non-nullable smile_version
CHANGELOG.md - Added new section "Ongoing"
- Included entry for avoiding None initialization for smile_version

Suggested labels

enhancement, quality

Suggested reviewers

  • CoMPaTech

Poem

🐰 Version's dance, no longer null,
Plugwise code now stands more tall
Strict types leap with joyful bound
No more None to trip us down!
Rabbit's code hops clean and bright 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 31b4aa5 and 763ade0.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jan 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (1800bc7) to head (763ade0).
Report is 6 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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:

  1. Using a named constant to clarify the intent
  2. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1800bc7 and 31b4aa5.

📒 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 to Version 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 to Version 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 to Version 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 to Version 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 valid Version 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

@bouwew bouwew changed the title Small improvement Avoid None-init for smile_version Jan 30, 2025
@bouwew bouwew marked this pull request as ready for review January 30, 2025 18:29
@bouwew bouwew requested a review from a team as a code owner January 30, 2025 18:29
Copy link

@bouwew bouwew merged commit 6fd4c97 into main Jan 31, 2025
19 checks passed
@bouwew bouwew deleted the nitpicks branch January 31, 2025 07:37
@coderabbitai coderabbitai bot mentioned this pull request Feb 4, 2025
This was referenced Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants