Skip to content

Commit 4212e87

Browse files
authored
chores(mypy): enforce and fix most rules (only 2 left) (#2285)
* update pyproject toml and fix strict_bytes errors * fixed 65 warn_unused_ignores errors * remove comment * ruff * ci fix * fix (last one for realsies)
1 parent a5dbabd commit 4212e87

File tree

42 files changed

+84
-82
lines changed

Some content is hidden

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

42 files changed

+84
-82
lines changed

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ exclude = [
190190
'^site/',
191191
]
192192
plugins = ["pydantic.mypy"]
193+
# more rules
194+
namespace_packages = true
195+
strict_optional = true
196+
strict_bytes = true
197+
warn_unused_ignores = true
198+
warn_unused_configs = true
199+
warn_redundant_casts = true
200+
ignore_missing_imports = false
193201

194202
[tool.codespell]
195203
skip = ".venv,__pycache__,.git,build,dist,*.pyc,*.lock"

src/cli/evm_bytes.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ def bytecode(self) -> Bytecode:
7171

7272

7373
def process_evm_bytes(evm_bytes: bytes) -> List[OpcodeWithOperands]: # noqa: D103
74-
evm_bytes = bytearray(evm_bytes)
74+
evm_bytes_array = bytearray(evm_bytes)
7575

7676
opcodes: List[OpcodeWithOperands] = []
7777

78-
while evm_bytes:
79-
opcode_byte = evm_bytes.pop(0)
78+
while evm_bytes_array:
79+
opcode_byte = evm_bytes_array.pop(0)
8080

8181
opcode: Op
8282
for op in Op:
@@ -93,21 +93,21 @@ def process_evm_bytes(evm_bytes: bytes) -> List[OpcodeWithOperands]: # noqa: D1
9393
opcode=opcode,
9494
operands=[
9595
int.from_bytes(
96-
evm_bytes[: opcode.data_portion_length], "big", signed=signed
96+
evm_bytes_array[: opcode.data_portion_length], "big", signed=signed
9797
)
9898
],
9999
)
100100
)
101-
evm_bytes = evm_bytes[opcode.data_portion_length :]
101+
evm_bytes_array = evm_bytes_array[opcode.data_portion_length :]
102102
elif opcode == Op.RJUMPV:
103-
if len(evm_bytes) == 0:
103+
if len(evm_bytes_array) == 0:
104104
opcodes.append(OpcodeWithOperands(opcode=opcode))
105105
else:
106-
max_index = evm_bytes.pop(0)
106+
max_index = evm_bytes_array.pop(0)
107107
operands: List[int] = []
108108
for _ in range(max_index + 1):
109-
operands.append(int.from_bytes(evm_bytes[:2], "big", signed=True))
110-
evm_bytes = evm_bytes[2:]
109+
operands.append(int.from_bytes(evm_bytes_array[:2], "big", signed=True))
110+
evm_bytes_array = evm_bytes_array[2:]
111111
opcodes.append(OpcodeWithOperands(opcode=opcode, operands=operands))
112112
else:
113113
opcodes.append(OpcodeWithOperands(opcode=opcode))

src/cli/extract_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def create_genesis_from_fixture(fixture_path: Path) -> Tuple[FixtureHeader, Allo
114114
chain_id = int(fixture.config.chain_id)
115115
else:
116116
pre_alloc_group = PreAllocGroup.model_validate(fixture_json)
117-
genesis = pre_alloc_group.genesis # type: ignore
117+
genesis = pre_alloc_group.genesis
118118
alloc = pre_alloc_group.pre
119119

120120
return genesis, alloc, chain_id

src/cli/order_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def recursive_sort(item: Dict[str, Any] | List[Any]) -> Dict[str, Any] | List[An
4141
return dict(sorted((k, recursive_sort(v)) for k, v in item.items()))
4242
elif isinstance(item, list):
4343
try:
44-
return sorted(cast(List[Any], [recursive_sort(x) for x in item]))
44+
return sorted(cast(List[Any], [recursive_sort(x) for x in item])) # type: ignore[redundant-cast]
4545
except TypeError:
4646
# If a TypeError is raised, we might be dealing with a list of
4747
# dictionaries Sort them based on their string representation

src/ethereum_clis/clis/besu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pathlib import Path
1010
from typing import ClassVar, Dict, Optional
1111

12-
import requests # type: ignore
12+
import requests
1313

1414
from ethereum_test_exceptions import (
1515
BlockException,

src/ethereum_test_fixtures/blockchain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def rlp(self) -> Bytes:
225225
"""Compute the RLP of the header."""
226226
return Bytes(eth_rlp.encode(self.rlp_encode_list))
227227

228-
@computed_field(alias="hash") # type: ignore[misc]
228+
@computed_field(alias="hash") # type: ignore[prop-decorator]
229229
@cached_property
230230
def block_hash(self) -> Hash:
231231
"""Compute the RLP of the header."""
@@ -481,7 +481,7 @@ class FixtureBlockBase(CamelModel):
481481
None, description="EIP-7928 Block Access List"
482482
)
483483

484-
@computed_field(alias="blocknumber") # type: ignore[misc]
484+
@computed_field(alias="blocknumber") # type: ignore[prop-decorator]
485485
@cached_property
486486
def block_number(self) -> Number:
487487
"""Get the block number from the header."""

src/ethereum_test_fixtures/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class FixtureAuthorizationTuple(
4545
):
4646
"""Authorization tuple for fixture transactions."""
4747

48-
v: ZeroPaddedHexNumber = Field(validation_alias=AliasChoices("v", "yParity")) # type: ignore
48+
v: ZeroPaddedHexNumber = Field(validation_alias=AliasChoices("v", "yParity"))
4949
r: ZeroPaddedHexNumber
5050
s: ZeroPaddedHexNumber
5151

src/ethereum_test_forks/tests/test_forks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def pre_allocation(cls, *, block_number: int = 0, timestamp: int = 0) -> Dict:
310310
return {"test2": "test2"} | super(PreAllocFork, cls).pre_allocation()
311311

312312

313-
@transition_fork(to_fork=PreAllocFork, at_timestamp=15_000) # type: ignore
313+
@transition_fork(to_fork=PreAllocFork, at_timestamp=15_000)
314314
class PreAllocTransitionFork(PrePreAllocFork):
315315
"""PrePreAllocFork to PreAllocFork transition at Timestamp 15k."""
316316

src/ethereum_test_forks/transition_base_fork.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def decorator(cls) -> Type[TransitionBaseClass]:
3939
assert issubclass(from_fork, BaseFork)
4040

4141
class NewTransitionClass(
42-
cls, # type: ignore
42+
cls,
4343
TransitionBaseClass,
4444
BaseFork,
4545
transition_tool_name=cls._transition_tool_name,

src/ethereum_test_specs/eof.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ def __init__(self, code: Bytes, expected: str, got: str):
118118
super().__init__(message)
119119

120120

121-
class EOFExceptionWithMessage(
122-
ExceptionWithMessage[EOFException] # type: ignore
123-
):
121+
class EOFExceptionWithMessage(ExceptionWithMessage[EOFException]):
124122
"""Exception returned from the eof validator with a message."""
125123

126124
pass

0 commit comments

Comments
 (0)