Skip to content

Commit a0129b0

Browse files
committed
update to run mypy local and update types as needed
1 parent 099e9d9 commit a0129b0

16 files changed

+80
-23
lines changed

.pre-commit-config.yaml

+7-4
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ repos:
4343
- id: mdformat
4444
additional_dependencies:
4545
- mdformat-gfm
46-
- repo: https://github.com/pre-commit/mirrors-mypy
47-
rev: v1.5.1
46+
- repo: local
4847
hooks:
49-
- id: mypy
50-
files: eth/
48+
- id: mypy-local
49+
name: run mypy with all dev dependencies present
50+
entry: python -m mypy -p eth
51+
language: system
52+
always_run: true
53+
pass_filenames: false
5154
- repo: https://github.com/PrincetonUniversity/blocklint
5255
rev: v0.2.5
5356
hooks:

.readthedocs.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ python:
1515
path: .
1616
extra_requirements:
1717
- docs
18+
- test
1819

1920
# Build all formats for RTD Downloads - htmlzip, pdf, epub
2021
formats: all

eth/consensus/clique/_utils.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import (
22
Iterable,
3+
cast,
34
)
45

56
from eth_keys import (
@@ -91,9 +92,12 @@ def get_block_signer(header: BlockHeaderAPI) -> Address:
9192

9293
signature = keys.Signature(signature_bytes=signature_bytes)
9394

94-
return signature.recover_public_key_from_msg_hash(
95-
signature_hash
96-
).to_canonical_address()
95+
return cast(
96+
Address,
97+
signature.recover_public_key_from_msg_hash(
98+
signature_hash
99+
).to_canonical_address(),
100+
)
97101

98102

99103
def is_in_turn(signer: Address, snapshot: Snapshot, header: BlockHeaderAPI) -> bool:

eth/consensus/clique/snapshot_manager.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949

5050
def make_snapshot_lookup_key(block_hash: Hash32) -> bytes:
51-
return f"block-hash-to-snapshot:{block_hash}".encode()
51+
return f"block-hash-to-snapshot:{block_hash!r}".encode()
5252

5353

5454
class SnapshotManager:
@@ -123,11 +123,11 @@ def apply(self, current_snapshot: Snapshot, header: BlockHeaderAPI) -> Snapshot:
123123
if tally.votes > len(snapshot.signers) / 2:
124124
if tally.action is VoteAction.NOMINATE:
125125
snapshot.signers.append(header.coinbase)
126-
self.logger.debug(f"New signer added: {header.coinbase}")
126+
self.logger.debug(f"New signer added: {header.coinbase!r}")
127127
else:
128128
if header.coinbase in snapshot.signers:
129129
snapshot.signers.remove(header.coinbase)
130-
self.logger.debug(f"Signer removed: {header.coinbase}")
130+
self.logger.debug(f"Signer removed: {header.coinbase!r}")
131131

132132
for vote in snapshot.votes.copy():
133133
# Discard any pending votes *from* the added or removed member

eth/db/chain.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ def _persist_block(
290290
uncles_hash = EMPTY_UNCLE_HASH
291291
if uncles_hash != block.header.uncles_hash:
292292
raise ValidationError(
293-
f"Block's uncles_hash ({block.header.uncles_hash}) does not match "
294-
f"actual uncles' hash ({uncles_hash})"
293+
f"Block's uncles_hash ({block.header.uncles_hash!r}) does not match "
294+
f"actual uncles' hash ({uncles_hash!r})"
295295
)
296296
new_canonical_hashes = tuple(header.hash for header in new_canonical_headers)
297297
old_canonical_hashes = tuple(header.hash for header in old_canonical_headers)

eth/db/schema.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def make_block_number_to_hash_lookup_key(block_number: BlockNumber) -> bytes:
2020

2121
@staticmethod
2222
def make_block_hash_to_score_lookup_key(block_hash: Hash32) -> bytes:
23-
return f"block-hash-to-score:{block_hash}".encode()
23+
return f"block-hash-to-score:{block_hash!r}".encode()
2424

2525
@staticmethod
2626
def make_header_chain_gaps_lookup_key() -> bytes:
@@ -39,8 +39,8 @@ def make_checkpoint_headers_key() -> bytes:
3939

4040
@staticmethod
4141
def make_transaction_hash_to_block_lookup_key(transaction_hash: Hash32) -> bytes:
42-
return f"transaction-hash-to-block:{transaction_hash}".encode()
42+
return f"transaction-hash-to-block:{transaction_hash!r}".encode()
4343

4444
@staticmethod
4545
def make_withdrawal_hash_to_block_lookup_key(withdrawal_hash: Hash32) -> bytes:
46-
return f"withdrawal-hash-to-block:{withdrawal_hash}".encode()
46+
return f"withdrawal-hash-to-block:{withdrawal_hash!r}".encode()

eth/precompiles/point_evaluation.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import hashlib
22
import os
3+
from typing import (
4+
cast,
5+
)
36

47
from ckzg import (
58
load_trusted_setup,
@@ -29,7 +32,9 @@
2932

3033

3134
def kzg_to_versioned_hash(commitment: bytes) -> Hash32:
32-
return VERSIONED_HASH_VERSION_KZG + hashlib.sha256(commitment).digest()[1:]
35+
return cast(
36+
Hash32, VERSIONED_HASH_VERSION_KZG + hashlib.sha256(commitment).digest()[1:]
37+
)
3338

3439

3540
def point_evaluation_precompile(computation: ComputationAPI) -> ComputationAPI:

eth/rlp/blocks.py

+27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import (
2+
Sequence,
23
Type,
34
)
45

@@ -12,13 +13,39 @@
1213
)
1314
from eth.abc import (
1415
BlockAPI,
16+
BlockHeaderAPI,
17+
SignedTransactionAPI,
1518
TransactionBuilderAPI,
19+
WithdrawalAPI,
1620
)
1721

1822

1923
class BaseBlock(Configurable, rlp.Serializable, BlockAPI):
2024
transaction_builder: Type[TransactionBuilderAPI] = None
2125

26+
def __init__(
27+
self,
28+
header: BlockHeaderAPI,
29+
transactions: Sequence[SignedTransactionAPI] = None,
30+
uncles: Sequence[BlockHeaderAPI] = None,
31+
withdrawals: Sequence[WithdrawalAPI] = None,
32+
) -> None:
33+
if withdrawals is not None:
34+
rlp.Serializable.__init__(
35+
self,
36+
header=header,
37+
transactions=transactions,
38+
uncles=uncles,
39+
withdrawals=withdrawals,
40+
)
41+
else:
42+
rlp.Serializable.__init__(
43+
self,
44+
header=header,
45+
transactions=transactions,
46+
uncles=uncles,
47+
)
48+
2249
@classmethod
2350
def get_transaction_builder(cls) -> Type[TransactionBuilderAPI]:
2451
if cls.transaction_builder is None:

eth/tools/fixtures/loading.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
from pytest import (
2+
Mark,
3+
MarkDecorator,
4+
)
15
import functools
26
import json
37
import os
48
from typing import (
59
Any,
610
Callable,
11+
Collection,
712
Dict,
813
Iterable,
914
Tuple,
15+
Union,
1016
)
1117

1218
from eth_utils import (
@@ -81,7 +87,9 @@ def load_fixture(
8187
def filter_fixtures(
8288
all_fixtures: Iterable[Any],
8389
fixtures_base_dir: str,
84-
mark_fn: Callable[[str, str], bool] = None,
90+
mark_fn: Callable[
91+
[str, str], Union[MarkDecorator, Collection[Union[MarkDecorator, Mark]], None]
92+
] = None,
8593
ignore_fn: Callable[..., bool] = None,
8694
) -> Any:
8795
"""

eth/tools/mining.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class POWMiningMixin(VirtualMachineAPI):
1515
"""
1616

1717
def finalize_block(self, block: BlockAPI) -> BlockAndMetaWitness:
18-
block_result = super().finalize_block(block)
18+
# type ignored because as a mixin, we expect to only use this with another
19+
# class that properly implements finalize_block
20+
block_result = super().finalize_block(block) # type: ignore[safe-super]
1921
block = block_result.block
2022

2123
nonce, mix_hash = pow.mine_pow_nonce(

eth/vm/forks/berlin/transactions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def max_fee_per_blob_gas(self) -> int:
282282
)
283283

284284
@property
285-
def blob_versioned_hashes(self) -> Hash32:
285+
def blob_versioned_hashes(self) -> Sequence[Hash32]:
286286
raise NotImplementedError(
287287
"blob_versioned_hashes is not implemented until Cancun."
288288
)
@@ -376,7 +376,7 @@ def max_fee_per_blob_gas(self) -> int:
376376
)
377377

378378
@property
379-
def blob_versioned_hashes(self) -> Hash32:
379+
def blob_versioned_hashes(self) -> Sequence[Hash32]:
380380
raise NotImplementedError(
381381
"blob_versioned_hashes is not implemented until Cancun."
382382
)

eth/vm/forks/cancun/constants.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from eth_typing import (
2+
Address,
3+
)
4+
15
HISTORY_BUFFER_LENGTH = 8191
2-
BEACON_ROOTS_ADDRESS = (
6+
BEACON_ROOTS_ADDRESS = Address(
37
b'\x00\x0f=\xf6\xd72\x80~\xf11\x9f\xb7\xb8\xbb\x85"\xd0\xbe\xac\x02'
48
)
59
BEACON_ROOTS_CONTRACT_CODE = b"3s\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x14`MW` 6\x14`$W__\xfd[_5\x80\x15`IWb\x00\x1f\xff\x81\x06\x90\x81T\x14`<W__\xfd[b\x00\x1f\xff\x01T_R` _\xf3[__\xfd[b\x00\x1f\xffB\x06B\x81U_5\x90b\x00\x1f\xff\x01U\x00" # noqa: E501

eth/vm/forks/london/transactions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def max_fee_per_blob_gas(self) -> int:
212212
)
213213

214214
@property
215-
def blob_versioned_hashes(self) -> Hash32:
215+
def blob_versioned_hashes(self) -> Sequence[Hash32]:
216216
raise NotImplementedError(
217217
"blob_versioned_hashes is not implemented until Cancun."
218218
)

newsfragments/2197.breaking.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adds running ``mypy`` locally with all deps installed, then updating typing as needed. Moves ``eth/tools/factories`` into ``tests`` as it is only ever used there.

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"build>=0.9.0",
1414
"bump_my_version>=0.19.0",
1515
"ipython",
16+
"mypy==1.10.0",
1617
"pre-commit>=3.4.0",
1718
"tox>=4.0.0",
1819
"twine",

tox.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ envlist=
99
py{38,39,310,311,312,313}-wheel
1010
windows-wheel
1111
docs
12-
py312-native-blockchain-{ \
12+
py313-native-blockchain-{ \
1313
metropolis, transition, frontier, homestead, tangerine_whistle, \
1414
spurious_dragon, byzantium, constantinople, petersburg, istanbul, \
1515
berlin, london, paris, shanghai, cancun \
@@ -65,6 +65,7 @@ allowlist_externals=make,pre-commit
6565

6666
[testenv:py{38,39,310,311,312,313}-lint]
6767
deps=pre-commit
68+
extras=dev
6869
commands=
6970
pre-commit install
7071
pre-commit run --all-files --show-diff-on-failure

0 commit comments

Comments
 (0)