fix: tighten typing on Card and Token dataclasses#188
Merged
Conversation
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
The
Card,Chapter,Track, andTokendataclasses had broken annotations likefield: str = None(assigningNoneto a non-Optionaltype) anddict[Track] = None(missing key type). mypy strict and pyright both flagged them, and downstream code (Home Assistantyotointegration) had to work around it withcard.chapters or {}everywhere.Changes
str = None→str | None = None, same forint.dict[Track]→dict[str, Track],dict[Chapter]→dict[str, Chapter].Card.id,Chapter.key,Track.key. They're always set at construction by the parser, and a card/chapter/track without an identifier doesn't exist in the Yoto model.chaptersandtrackstofield(default_factory=dict)instead ofNone. A card always has chapters and a chapter always has tracks in the Yoto data model; theNonewas only an artifact of incremental parsing. Empty dict represents the "not yet loaded" state.is Noneguards inclient.pyandor {}in the e2e test.Impact
No runtime behavior change. Pure annotation tightening plus removal of dead guards.
Downstream consumers (HA core integration) can drop their
card.chapters or {}defensive code and trust the type.