STARBackend: make iSWAPInformation immutable#1066
Merged
Merged
Conversation
iSWAPInformation is built once in a single expression at every call site; no code reassigns its fields. Declaring it frozen=True enforces that structurally. Uses eq=False so __eq__ and __hash__ stay identity-based; otherwise the dict-valued fields would trip the auto-generated __hash__. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
|
there are probably more classes that benefit from this |
Collaborator
Author
|
Yes, I completely agree, but for i.e. this is just the start which we have high confidence in being ready right now |
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.
Follow-up to #1055, addressing the
frozen=Truehalf of @burnpanck's@dataclass(kw_only=True, frozen=True)suggestion.iSWAPInformationis constructed in a single expression at every call site (_set_up_iswapinlines all firmware queries as kwargs; chatterbox and tests pass literals) - never built incrementally - and no code reassigns its fields. Declaring itfrozenenforces immutability structurally: accidental field writes raiseFrozenInstanceErrorinstead of silently corrupting a record that downstream code treats as a single source of truth.eq=Falsebecause two fields are dicts (rotation_drive_predefined_increments,wrist_drive_predefined_increments); the defaultfrozen=True, eq=Truewould auto-generate a__hash__that raisesTypeError: unhashable type: 'dict'the first time an instance is hashed (latent today, but a trap for future use as a dict key or set member). Witheq=False,__eq__and__hash__fall back toobject's identity-based defaults, which matches how existing call sites and tests use the record (assertIs, never field-by-field equality).kw_only=Truefrom the same suggestion is deferred: it requires Python 3.10+, andpyproject.tomldeclaresrequires-python = ">=3.9"(CI lint and typecheck both run on 3.9).Behaviour-equivalent.
Part 22 of the "Tame the iSWAP" epic:
https://discuss.pylabrobot.org/t/intro-to-epic-tame-the-iswap/517