refactor: drop from __future__ import annotations in Pydantic-defining files#752
Merged
tcoratger merged 1 commit intoMay 21, 2026
Merged
Conversation
…g files The project rule (CLAUDE.md, "Pydantic + from __future__ import annotations") bans the lazy-annotations import in files that define Pydantic Container or SSZModel classes, because lazy strings break model resolution for forward references. Eight audit-flagged files still carried it. Forward-reference fixes needed once annotations evaluate eagerly: - subtree.py: four classmethod constructors returning HashSubTree now annotated as Self (added from typing import Self). The methods are pure classmethod factories on the class itself, so Self is the cleanest fit and avoids quoting noise. - aggregation.py: five forward references to TypeOneMultiSignature and TypeTwoMultiSignature inside the class bodies became quoted strings, since the class isn't bound at the point those signatures are evaluated. Files whose future import alone was redundant (no forward refs): byte_arrays.py, bitfields.py, collections.py, ssz_base.py, container.py, xmss/containers.py. Audit's "Plus check" list (participation.py, validator.py, checkpoint.py) already did not carry the import. Co-Authored-By: Claude Opus 4.7 (1M context) <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
CLAUDE.md rule R1 bans
from __future__ import annotationsin files that define Pydantic Container or SSZModel classes, because lazy-string annotations break Pydantic's forward-reference resolution. Eight audit-flagged files still carried it; this PR removes it from all of them.Forward-reference fixes (annotations now evaluate eagerly)
subspecs/xmss/subtree.py— four classmethod constructors that returnedHashSubTreenow returnSelf(addedfrom typing import Self). The methods are pure classmethod factories on the class itself, soSelfreads cleaner than quoting.subspecs/xmss/aggregation.py— five forward references toTypeOneMultiSignatureandTypeTwoMultiSignatureinside their own class bodies became quoted strings ("TypeOneMultiSignature","TypeTwoMultiSignature"), since the class isn't bound at the point the signatures are evaluated.Files whose future import alone was redundant
types/byte_arrays.py,types/bitfields.py,types/collections.py,types/ssz_base.py,types/container.py,subspecs/xmss/containers.py— no forward-reference fixes needed.Audit "Plus check" list
participation.py,validator.py,checkpoint.pydid not actually carry the future import. No change needed there.Test plan
ruff check src/lean_spec/types/ src/lean_spec/subspecs/xmss/— clean.uv run pytest tests/lean_spec/types/ tests/lean_spec/subspecs/xmss/— 1056 tests pass.🤖 Generated with Claude Code