Skip to content

Commit d70d1bb

Browse files
tcoratgerclaude
andauthored
refactor: drop from __future__ import annotations in Pydantic-defining files (leanEthereum#759)
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>
1 parent 6513aba commit d70d1bb

6 files changed

Lines changed: 4 additions & 14 deletions

File tree

src/lean_spec/forks/lstar/containers/attestation/attestation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
Attestations can be aggregated by common data to save space and bandwidth.
1212
"""
1313

14-
from __future__ import annotations
15-
1614
from lean_spec.subspecs.xmss.aggregation import TypeOneMultiSignature
1715
from lean_spec.subspecs.xmss.containers import Signature
1816
from lean_spec.types import AggregationBits, Checkpoint, Container, Slot, ValidatorIndex

src/lean_spec/forks/lstar/containers/block/types.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Block-specific SSZ types for the Lean Ethereum consensus specification."""
22

3-
from __future__ import annotations
4-
53
from lean_spec.subspecs.chain.config import VALIDATOR_REGISTRY_LIMIT
64
from lean_spec.types import SSZList
75

src/lean_spec/forks/lstar/containers/state/state.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""State Container for the Lean Ethereum consensus specification."""
22

3-
from __future__ import annotations
4-
53
from lean_spec.forks.lstar.containers.block import BlockHeader
64
from lean_spec.forks.lstar.containers.config import Config
75
from lean_spec.forks.lstar.containers.state.types import (

src/lean_spec/forks/lstar/containers/state/types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""State-specific SSZ types for the Lean Ethereum consensus specification."""
22

3-
from __future__ import annotations
3+
from typing import Self
44

55
from lean_spec.subspecs.chain.config import HISTORICAL_ROOTS_LIMIT, VALIDATOR_REGISTRY_LIMIT
66
from lean_spec.types import Boolean, Bytes32, Slot, SSZList
@@ -67,7 +67,7 @@ def with_justified(
6767
finalized_slot: Slot,
6868
target_slot: Slot,
6969
value: Boolean,
70-
) -> JustifiedSlots:
70+
) -> Self:
7171
"""
7272
Return a new bitfield with the justification status updated.
7373
@@ -112,7 +112,7 @@ def with_justified(
112112

113113
return self.model_copy(update={"data": new_data})
114114

115-
def extend_to_slot(self, finalized_slot: Slot, target_slot: Slot) -> JustifiedSlots:
115+
def extend_to_slot(self, finalized_slot: Slot, target_slot: Slot) -> Self:
116116
"""
117117
Extend the tracking capacity to cover a new target slot.
118118
@@ -147,7 +147,7 @@ def extend_to_slot(self, finalized_slot: Slot, target_slot: Slot) -> JustifiedSl
147147
# We extend the existing data with False values to bridge the gap.
148148
return self.model_copy(update={"data": list(self.data) + [Boolean(False)] * gap_size})
149149

150-
def shift_window(self, delta: int) -> JustifiedSlots:
150+
def shift_window(self, delta: int) -> Self:
151151
"""
152152
Advance the tracking window by dropping slots that became finalized.
153153

src/lean_spec/forks/lstar/containers/validator.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Validator container for the Lean Ethereum consensus specification."""
22

3-
from __future__ import annotations
4-
53
from lean_spec.subspecs.chain.config import VALIDATOR_REGISTRY_LIMIT
64
from lean_spec.subspecs.xmss.containers import PublicKey
75
from lean_spec.types import Bytes52, Container, SSZList, ValidatorIndex

src/lean_spec/subspecs/xmss/rand.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Random data generator for the XMSS signature scheme."""
22

3-
from __future__ import annotations
4-
53
import secrets
64

75
from lean_spec.types import StrictBaseModel

0 commit comments

Comments
 (0)