Add PEP 561 typing to enable static type checking for consumers#147
Open
johanzander wants to merge 3 commits into
Open
Add PEP 561 typing to enable static type checking for consumers#147johanzander wants to merge 3 commits into
johanzander wants to merge 3 commits into
Conversation
Add py.typed marker file, from __future__ import annotations to all modules, and type annotations to all public functions across the library. This enables Home Assistant strict-typing quality scale compliance and allows type checkers (mypy, pyright) to validate code using this package. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adding type annotations surfaced FBT001 (boolean positional arguments) on pre-existing function signatures. These cannot be changed without breaking the public API, so suppress the rule globally alongside the already-ignored FBT002. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replaces the verbose `str | float | bool | list[Any] | dict[str, Any]` union with a named `ParameterValue` type alias defined in abstract_device.py and used across min, sph, and OpenApiV1. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds PEP 561 typing support so that type checkers (mypy, pyright) can validate code that uses this library. Without this, callers get
Anyfor every function call — typos in parameter names, wrong argument types, and missing required arguments are only caught at runtime when the Growatt API returns an error (or silently does the wrong thing).What this enables:
api.login(username=123, password=pwd)orapi.plant_detail(plant_id, "invalid")at development timetype: ignoresuppressionsChanges:
py.typedmarker file and include it in package datafrom __future__ import annotationsto all modulesParameterValuetype alias for the recurring write parameter union typeFBT001to ruff ignore list (boolean positional args are part of the existing public API)Risk: Zero logic changes. Every diff line is either an import or a function signature annotation. With
from __future__ import annotations, annotations are stored as strings and never evaluated at runtime — the package behaves identically to before.Test plan
ruff checkpasses clean🤖 Generated with Claude Code