Skip to content

Add PEP 561 typing to enable static type checking for consumers#147

Open
johanzander wants to merge 3 commits into
indykoning:masterfrom
johanzander:pep561-typing
Open

Add PEP 561 typing to enable static type checking for consumers#147
johanzander wants to merge 3 commits into
indykoning:masterfrom
johanzander:pep561-typing

Conversation

@johanzander
Copy link
Copy Markdown
Collaborator

@johanzander johanzander commented May 23, 2026

Summary

Adds PEP 561 typing support so that type checkers (mypy, pyright) can validate code that uses this library. Without this, callers get Any for 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:

  • Type checkers can now catch bugs like api.login(username=123, password=pwd) or api.plant_detail(plant_id, "invalid") at development time
  • IDE autocompletion now shows correct parameter names, types, and return types
  • Downstream projects (e.g. Home Assistant integrations) that run strict type checking can use this library without type: ignore suppressions

Changes:

  • Add py.typed marker file and include it in package data
  • Add from __future__ import annotations to all modules
  • Add type annotations to all public functions (~100 signatures across 7 files)
  • Extract ParameterValue type alias for the recurring write parameter union type
  • Add FBT001 to 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

  • All package imports verified working
  • ruff check passes clean
  • Diff audited: confirmed zero logic changes, only annotations and imports

🤖 Generated with Claude Code

johanzander and others added 3 commits May 24, 2026 00:11
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>
@johanzander johanzander changed the title Add PEP 561 typing support Add PEP 561 typing to enable static type checking for consumers May 23, 2026
@johanzander johanzander marked this pull request as ready for review May 23, 2026 22:32
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.

1 participant