diff --git a/src/lean_spec/forks/lstar/store.py b/src/lean_spec/forks/lstar/store.py index 79321c0d..d4829093 100644 --- a/src/lean_spec/forks/lstar/store.py +++ b/src/lean_spec/forks/lstar/store.py @@ -4,9 +4,9 @@ The Store tracks all information required for the LMD GHOST forkchoice algorithm. """ -__all__ = ["AttestationSignatureEntry", "BlockT", "StateT", "Store"] +__all__ = ["AttestationSignatureEntry", "Store"] -from typing import Generic, NamedTuple, TypeVar +from typing import NamedTuple from pydantic import Field @@ -21,12 +21,6 @@ from lean_spec.types.base import StrictBaseModel from lean_spec.types.container import Container -StateT = TypeVar("StateT", bound=Container) -"""Per-fork post-state type tracked alongside each known block.""" - -BlockT = TypeVar("BlockT", bound=Container) -"""Per-fork block type stored in the forkchoice view.""" - class AttestationSignatureEntry(NamedTuple): """ @@ -40,7 +34,7 @@ class AttestationSignatureEntry(NamedTuple): signature: Signature -class Store(StrictBaseModel, Generic[StateT, BlockT]): +class Store[StateT: Container, BlockT: Container](StrictBaseModel): """ Forkchoice store tracking chain state and validator attestations. diff --git a/src/lean_spec/types/collections.py b/src/lean_spec/types/collections.py index f83b33b9..26350bcf 100644 --- a/src/lean_spec/types/collections.py +++ b/src/lean_spec/types/collections.py @@ -8,10 +8,8 @@ IO, Any, ClassVar, - Generic, Protocol, Self, - TypeVar, cast, overload, override, @@ -38,14 +36,6 @@ class IntFieldElement(Protocol): value: int -T = TypeVar("T", bound=SSZType) -"""Generic type parameter for SSZ collection elements. - -Bound to SSZType to ensure elements are valid SSZ types. -Enables type checkers to infer correct return types for indexed access. -""" - - def _extract_element_type_from_generic(cls: type, origin_class: type) -> type[SSZType] | None: """Extract ELEMENT_TYPE from Pydantic's generic metadata.""" for base in cls.__bases__: @@ -94,7 +84,7 @@ def _validate_offsets(offsets: list[int], scope: int, type_name: str) -> None: ) -class SSZVector(SSZModel, Generic[T]): +class SSZVector[T: SSZType](SSZModel): """Fixed-length, immutable SSZ sequence. Contains exactly LENGTH elements of type ELEMENT_TYPE. @@ -260,7 +250,7 @@ def elements(self) -> list[T]: return list(self.data) -class SSZList(SSZModel, Generic[T]): +class SSZList[T: SSZType](SSZModel): """Variable-length SSZ sequence with a maximum capacity. Contains between 0 and LIMIT elements of type ELEMENT_TYPE.