Skip to content

Commit 9bf2d2e

Browse files
tcoratgerclaude
andauthored
refactor: standardize on absolute imports repo-wide (leanEthereum#823)
Convert all intra-package relative imports to absolute and enforce the convention so it cannot regress. Motivation: ruff's import combining works on the literal module-path string, so a relative and an absolute import of the same module (e.g. `from .containers import Interval` next to `from lean_spec.spec.forks.lstar.containers import ...`) were never merged. The package mixed both styles, which defeated auto-combining and produced duplicate import blocks. Absolute imports are the more standardized choice: PEP 8 recommends them, Google's style guide bans relative imports outright, and the CPython standard library uses absolute throughout. Changes: - Enable flake8-tidy-imports `ban-relative-imports = "all"` and add `TID` to ruff's select/fixable lists, so relative imports are now a lint error. - Convert ~660 relative imports across 132 files to absolute via ruff's TID252 autofix, then re-sort with isort. - Fix two namespace-package roots the autofix mis-resolved (`tests/` has no `__init__.py` chain): `helpers.*` and `gossipsub.*` now use their full `tests.lean_spec.*` paths. `just check` passes (ruff, ruff format, ty, codespell, mdformat). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 724cb77 commit 9bf2d2e

132 files changed

Lines changed: 425 additions & 478 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/testing/src/consensus_testing/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from typing import Type
44

5-
from . import forks
6-
from .genesis import build_anchor, generate_pre_state
7-
from .test_fixtures import (
5+
from consensus_testing import forks
6+
from consensus_testing.genesis import build_anchor, generate_pre_state
7+
from consensus_testing.test_fixtures import (
88
ApiEndpointTest,
99
BaseConsensusFixture,
1010
DropComponentMessageBinding,
@@ -28,7 +28,7 @@
2828
VerifySignaturesTest,
2929
VerifySingleMessageProofsTest,
3030
)
31-
from .test_types import (
31+
from consensus_testing.test_types import (
3232
AggregatedAttestationCheck,
3333
AggregatedAttestationSpec,
3434
AttestationCheck,

packages/testing/src/consensus_testing/forks/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from framework.forks import BaseFork, BaseForkMeta, ForkRegistry
66

7-
from . import forks as _forks_module
8-
from .forks import Lstar
7+
from consensus_testing.forks import forks as _forks_module
8+
from consensus_testing.forks.forks import Lstar
99

1010
Fork = Type[BaseFork]
1111

packages/testing/src/consensus_testing/genesis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Consensus layer pre-state generation."""
22

3+
from consensus_testing.keys import XmssKeyManager
34
from lean_spec.spec.crypto.merkleization import hash_tree_root
45
from lean_spec.spec.forks import Slot, ValidatorIndex
56
from lean_spec.spec.forks.lstar.containers import (
@@ -13,8 +14,6 @@
1314
from lean_spec.spec.forks.lstar.spec import LstarSpec
1415
from lean_spec.spec.ssz import Bytes52, Uint64
1516

16-
from .keys import XmssKeyManager
17-
1817
_DEFAULT_GENESIS_TIME = Uint64(0)
1918

2019

packages/testing/src/consensus_testing/test_fixtures/__init__.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
"""Consensus test fixture format definitions (Pydantic models)."""
22

3-
from .api_endpoint import ApiEndpointTest
4-
from .base import BaseConsensusFixture
5-
from .fork_choice import ForkChoiceTest
6-
from .gossipsub_handler import GossipsubHandlerTest
7-
from .justifiability import JustifiabilityTest
8-
from .networking_codec import NetworkingCodecTest
9-
from .poseidon_permutation import PoseidonPermutationTest
10-
from .slot_clock import SlotClockTest
11-
from .ssz import SSZTest
12-
from .state_transition import StateTransitionTest
13-
from .sync import SyncTest
14-
from .verify_multi_message_proofs import (
3+
from consensus_testing.test_fixtures.api_endpoint import ApiEndpointTest
4+
from consensus_testing.test_fixtures.base import BaseConsensusFixture
5+
from consensus_testing.test_fixtures.fork_choice import ForkChoiceTest
6+
from consensus_testing.test_fixtures.gossipsub_handler import GossipsubHandlerTest
7+
from consensus_testing.test_fixtures.justifiability import JustifiabilityTest
8+
from consensus_testing.test_fixtures.networking_codec import NetworkingCodecTest
9+
from consensus_testing.test_fixtures.poseidon_permutation import PoseidonPermutationTest
10+
from consensus_testing.test_fixtures.slot_clock import SlotClockTest
11+
from consensus_testing.test_fixtures.ssz import SSZTest
12+
from consensus_testing.test_fixtures.state_transition import StateTransitionTest
13+
from consensus_testing.test_fixtures.sync import SyncTest
14+
from consensus_testing.test_fixtures.verify_multi_message_proofs import (
1515
DropComponentMessageBinding,
1616
IncrementComponentSlot,
1717
RebindComponentToAlternateHeadRoot,
1818
SwapComponentMessageBindings,
1919
SwapComponentParticipantPublicKey,
2020
VerifyMultiMessageProofsTest,
2121
)
22-
from .verify_signatures import VerifySignaturesTest
23-
from .verify_single_message_proofs import (
22+
from consensus_testing.test_fixtures.verify_signatures import VerifySignaturesTest
23+
from consensus_testing.test_fixtures.verify_single_message_proofs import (
2424
IncrementEmittedSlot,
2525
RebindToAlternateHeadRoot,
2626
SwapParticipantPublicKey,

packages/testing/src/consensus_testing/test_fixtures/api_endpoint.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
from collections.abc import Callable
44
from typing import Any, ClassVar
55

6+
from consensus_testing.genesis import build_anchor, generate_pre_state
7+
from consensus_testing.test_fixtures.base import BaseConsensusFixture
68
from lean_spec.spec.crypto.merkleization import hash_tree_root
79
from lean_spec.spec.forks import Slot, ValidatorIndex
810
from lean_spec.spec.forks.lstar import Store
911
from lean_spec.spec.forks.lstar.containers import AggregatedAttestations, Block, BlockBody, State
1012
from lean_spec.spec.forks.lstar.spec import LstarSpec
1113
from lean_spec.spec.ssz import Bytes32, Uint64
1214

13-
from ..genesis import build_anchor, generate_pre_state
14-
from .base import BaseConsensusFixture
15-
1615
EndpointHandler = Callable[[Store, "ApiEndpointTest"], dict[str, Any]]
1716
"""Uniform signature for all endpoint response builders.
1817

packages/testing/src/consensus_testing/test_fixtures/fork_choice.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111

1212
from pydantic import Field, model_validator
1313

14+
from consensus_testing.keys import XmssKeyManager
15+
from consensus_testing.test_fixtures.base import BaseConsensusFixture
16+
from consensus_testing.test_types import (
17+
AttestationStep,
18+
BlockStep,
19+
ForkChoiceStep,
20+
GossipAggregatedAttestationStep,
21+
TickStep,
22+
)
1423
from lean_spec.node.chain.clock import SlotClock
1524
from lean_spec.spec.crypto.merkleization import hash_tree_root
1625
from lean_spec.spec.forks import Interval, Slot, ValidatorIndex
@@ -23,18 +32,6 @@
2332
)
2433
from lean_spec.spec.forks.lstar.spec import LstarSpec
2534

26-
from ..keys import (
27-
XmssKeyManager,
28-
)
29-
from ..test_types import (
30-
AttestationStep,
31-
BlockStep,
32-
ForkChoiceStep,
33-
GossipAggregatedAttestationStep,
34-
TickStep,
35-
)
36-
from .base import BaseConsensusFixture
37-
3835

3936
class ForkChoiceTest(BaseConsensusFixture):
4037
"""

packages/testing/src/consensus_testing/test_fixtures/gossipsub_handler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from typing import Any, ClassVar
1414
from unittest.mock import patch
1515

16+
from consensus_testing.test_fixtures.base import BaseConsensusFixture
1617
from lean_spec.node.networking import PeerId
1718
from lean_spec.node.networking.gossipsub.behavior import GossipsubBehavior, PeerState
1819
from lean_spec.node.networking.gossipsub.message import GossipsubMessage
@@ -29,8 +30,6 @@
2930
)
3031
from lean_spec.node.networking.gossipsub.types import MessageId, Timestamp, TopicId
3132

32-
from .base import BaseConsensusFixture
33-
3433
# Sentinel that satisfies `outbound_stream is not None` checks.
3534
# The patched _send_rpc never touches the stream, so any non-None value works.
3635
_FAKE_STREAM: Any = object()

packages/testing/src/consensus_testing/test_fixtures/justifiability.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313

1414
from typing import Any, ClassVar
1515

16+
from consensus_testing.test_fixtures.base import BaseConsensusFixture
1617
from lean_spec.spec.forks import Slot
1718

18-
from .base import BaseConsensusFixture
19-
2019

2120
class JustifiabilityTest(BaseConsensusFixture):
2221
"""Fixture for 3SF-mini justifiability conformance.

packages/testing/src/consensus_testing/test_fixtures/networking_codec.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import Any, ClassVar
44

5+
from consensus_testing.test_fixtures.base import BaseConsensusFixture
56
from lean_spec.node.networking.enr.enr import ENR
67
from lean_spec.node.networking.gossipsub.message import GossipsubMessage
78
from lean_spec.node.networking.gossipsub.rpc import (
@@ -27,8 +28,6 @@
2728
from lean_spec.node.snappy import compress, decompress, frame_compress, frame_decompress
2829
from lean_spec.spec.forks import SubnetId
2930

30-
from .base import BaseConsensusFixture
31-
3231

3332
def _to_hex(data: bytes) -> str:
3433
"""Format raw bytes as a 0x-prefixed hex string."""

packages/testing/src/consensus_testing/test_fixtures/poseidon_permutation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77

88
from typing import Any, ClassVar
99

10+
from consensus_testing.test_fixtures.base import BaseConsensusFixture
1011
from lean_spec.spec.crypto.koalabear import Fp
1112
from lean_spec.spec.crypto.poseidon import PARAMS_16, PARAMS_24, Poseidon
1213

13-
from .base import BaseConsensusFixture
14-
1514

1615
class PoseidonPermutationTest(BaseConsensusFixture):
1716
"""Fixture for Poseidon permutation conformance.

0 commit comments

Comments
 (0)