Skip to content

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

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/claude-md-violations
May 22, 2026
Merged

refactor: drop from __future__ import annotations in Pydantic-defining files#759
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/claude-md-violations

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. Six audit-flagged files still carried it.

  • forks/lstar/containers/validator.py
  • forks/lstar/containers/state/types.py — small adjustment alongside the drop: three classmethod-like helpers on JustifiedSlots returned the class by name (-> JustifiedSlots). Without future annotations the bare name is undefined at signature evaluation, so they switch to typing.Self, which reads cleaner anyway for self-referential factories.
  • forks/lstar/containers/state/state.py
  • forks/lstar/containers/attestation/attestation.py
  • forks/lstar/containers/block/types.py
  • subspecs/xmss/rand.py

Items deliberately skipped

  • R2 (Store = LstarStore alias in forks/__init__.py) — the audit framed it as a backwards-compat shim, but per Multi-fork architecture: roadmap and tracking issue #686 the alias is the public generic name that lets subspecs (sync/, api/, node/, ...) reference "the current fork's Store" without importing forks.lstar.*. Dropping it would couple subspecs to the concrete fork and defeat the multi-fork architecture.
  • R3 (QUIC random peer-id anti-pattern in transport/quic/connection.py) — needs real libp2p TLS extension parsing (X.509 extension OID 1.3.6.1.4.1.53594.1.1, signature verification over the TLS public key, PeerId derivation). Affects both client and server paths and belongs in its own focused PR.

Test plan

  • ruff check, ruff format --check, ty check — all clean.
  • uv run pytest tests/lean_spec/forks/ tests/lean_spec/subspecs/sync/ tests/lean_spec/subspecs/api/ tests/lean_spec/subspecs/node/ tests/lean_spec/subspecs/xmss/ — 455 tests pass.
  • uv run fill tests/consensus/lstar/fc/test_tick_system.py::test_tick_interval_progression_through_full_slot --fork=Lstar — 1 passed in 9.25s.

🤖 Generated with Claude Code

…g files

CLAUDE.md rule R1 bans the lazy-annotations import in files that
define Pydantic Container or SSZModel classes; lazy-string
annotations break Pydantic's forward-reference resolution. Six
audit-flagged files still carried it.

state/types.py needed a small adjustment after the drop: three
classmethod-like helpers on JustifiedSlots returned the class by
name (-> JustifiedSlots). Without future annotations the bare name
is undefined at signature evaluation, so they switch to typing.Self
which reads cleaner anyway for self-referential factories.

R2 (Store = LstarStore alias) is intentionally left alone. The
alias is the public generic name that lets subspecs (sync, api,
node, ...) reference "the current fork's Store" without importing
forks.lstar.*. Removing it would couple subspecs to the concrete
fork, defeating the multi-fork architecture (leanEthereum#686).

R3 (QUIC random peer-id anti-pattern) needs real libp2p TLS
extension parsing and belongs in its own PR.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tcoratger tcoratger merged commit d70d1bb into leanEthereum:main May 22, 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