Skip to content

TypingTyping: add TypedDicts and pass mypy --strict#43

Merged
oyvindwe merged 3 commits into
echoromeo:masterfrom
oyvindwe:typing-cleanup
May 14, 2026
Merged

TypingTyping: add TypedDicts and pass mypy --strict#43
oyvindwe merged 3 commits into
echoromeo:masterfrom
oyvindwe:typing-cleanup

Conversation

@oyvindwe
Copy link
Copy Markdown
Collaborator

@oyvindwe oyvindwe commented May 3, 2026

Required for Home Assistant Platinum quality - see Strict typing

  • Ship TypedDicts for hub.zones / components / week_profiles / overrides / hub_info so consumers get static field types.
  • Tighten remaining annotations
  • Add mypy --strict to GitHub Actions

Static-typing notes for consumers under strict mypy:

  • TypedDicts are not assignable to dict[str, Any]. Switch parameter types to Mapping[str, Any] or the new TypedDicts.
  • zone.values() narrows from Any to object.
  • Unknown / variable-keyed lookups (zone["custom_key"], zone[some_var]) are rejected where they were previously Any.

- Ship TypedDicts for hub.zones / components / week_profiles / overrides
  / hub_info so consumers get static field types.
- Tighten remaining annotations
- Add mypy --strict to GitHub Actions

Static-typing notes for consumers under strict mypy:

- TypedDicts are not assignable to dict[str, Any]. Switch parameter
  types to Mapping[str, Any] or the new TypedDicts.
- zone.values() narrows from Any to object.
- Unknown / variable-keyed lookups (zone["custom_key"], zone[some_var])
  are rejected where they were previously Any.
@oyvindwe oyvindwe requested a review from capelevy May 3, 2026 10:08
@oyvindwe oyvindwe mentioned this pull request May 3, 2026
@oyvindwe
Copy link
Copy Markdown
Collaborator Author

oyvindwe commented May 4, 2026

I have verified that nobo_hub validates with strict mypy checking with this change.

Ready to merge and ship 1.9.0! 🚀

Comment thread pynobo/__init__.py Outdated
def type(
self,
) -> Literal[
"THERMOSTAT_HEATER",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Third time we are repeating the actual strings, anything we can do to avoid this? Adding THERMOSTAT_HEATER: Final[Literal["THERMOSTAT_HEATER"]] = "THERMOSTAT_HEATER"
or something to the declaration lines seems stupid, but python must have some better way of doing this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. We can create a ModelType alias for the typing to reduce to 2 repetitions.

Avoiding the last repetition requires an API change - taking a note to fix this in 2.0.0.

Copy link
Copy Markdown
Collaborator

@capelevy capelevy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for updating. Looks good :)

@oyvindwe oyvindwe merged commit e2965fb into echoromeo:master May 14, 2026
6 checks passed
@oyvindwe oyvindwe deleted the typing-cleanup branch May 14, 2026 06:08
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