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
unnawut added a commit to unnawut/leanSpec that referenced this pull request May 28, 2026
Brings the new fixture in line with the patterns the other consensus
test fixtures follow:

- Drop ``from __future__ import annotations`` (PR leanEthereum#759 removed it from
  Pydantic-defining files); quote the one self-reference instead.
- Replace the bespoke ``expect_valid: bool`` field with the inherited
  ``expect_exception`` field already used by SSZTest, NetworkingCodec,
  and VerifySignaturesTest. Rejection vectors now pin
  ``AggregationError`` and the framework serializes the class name to
  JSON.
- Switch the tamper dispatch in ``_apply_tamper`` from ``if/elif`` to
  ``match/case`` to follow the pattern in slot_clock and
  networking_codec.
- Expand the module-level docstring from one line to a short
  paragraph describing what the fixture covers.
- Normalize the ``public_keys`` default from ``[]`` to ``| None =
  None`` to match every other output field on the model.
unnawut added a commit to unnawut/leanSpec that referenced this pull request May 28, 2026
Brings the new fixture in line with the patterns the other consensus
test fixtures follow:

- Drop ``from __future__ import annotations`` (PR leanEthereum#759 removed it from
  Pydantic-defining files); quote the one self-reference instead.
- Replace the bespoke ``expect_valid: bool`` field with the inherited
  ``expect_exception`` field already used by SSZTest, NetworkingCodec,
  and VerifySignaturesTest. Rejection vectors now pin
  ``AggregationError`` and the framework serializes the class name to
  JSON.
- Switch the tamper dispatch in ``_apply_tamper`` from ``if/elif`` to
  ``match/case`` to follow the pattern in slot_clock and
  networking_codec.
- Expand the module-level docstring from one line to a short
  paragraph describing what the fixture covers.
- Normalize the ``public_keys`` default from ``[]`` to ``| None =
  None`` to match every other output field on the model.
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