Skip to content

refactor: drop from __future__ import annotations in Pydantic-defining files#752

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/drop-future-annotations
May 21, 2026
Merged

refactor: drop from __future__ import annotations in Pydantic-defining files#752
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/drop-future-annotations

Conversation

@tcoratger
Copy link
Copy Markdown
Collaborator

Summary

CLAUDE.md rule R1 bans from __future__ import annotations in 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 returned HashSubTree now return Self (added from typing import Self). The methods are pure classmethod factories on the class itself, so Self reads cleaner than quoting.
  • subspecs/xmss/aggregation.py — five forward references to TypeOneMultiSignature and TypeTwoMultiSignature inside 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.py did 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

…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>
@tcoratger tcoratger merged commit 5f8008a into leanEthereum:main May 21, 2026
13 checks passed
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