Skip to content

Commit 56953c9

Browse files
committed
Disallow unused arguments (closes #962)
1 parent 5de14b5 commit 56953c9

File tree

12 files changed

+46
-34
lines changed

12 files changed

+46
-34
lines changed

setup.cfg

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ python_requires = >=3.10
125125
install_requires =
126126
pycryptodome>=3,<4
127127
coincurve>=20,<21
128-
typing_extensions>=4.2
128+
typing_extensions>=4.4
129129
py-ecc>=8.0.0b2,<9
130130
ethereum-types>=0.2.1,<0.3
131131
ethereum-rlp>=0.1.1,<0.2
@@ -181,6 +181,7 @@ lint =
181181
flake8-bugbear==23.12.2
182182
flake8-docstrings==1.7.0
183183
flake8-spellcheck==0.28.0
184+
flake8-unused-arguments==0.0.13
184185

185186
tools =
186187
platformdirs>=4.2,<5
@@ -197,6 +198,7 @@ optimized =
197198
dictionaries=en_US,python,technical
198199
docstring-convention = all
199200
extend-ignore =
201+
U101
200202
E203
201203
D107
202204
D200
@@ -221,4 +223,9 @@ extend-exclude =
221223
per-file-ignores =
222224
tests/*:D100,D101,D103,D104,E501,SC100,SC200
223225

226+
unused-arguments-ignore-abstract-functions = true
227+
unused-arguments-ignore-override-functions = true
228+
unused-arguments-ignore-overload-functions = true
229+
unused-arguments-ignore-dunder = true
230+
224231
# vim: set ft=dosini:

src/ethereum/cancun/vm/instructions/system.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def generic_create(
6565
contract_address: Address,
6666
memory_start_position: U256,
6767
memory_size: U256,
68-
init_code_gas: Uint,
6968
) -> None:
7069
"""
7170
Core logic used by the `CREATE*` family of opcodes.
@@ -182,7 +181,6 @@ def create(evm: Evm) -> None:
182181
contract_address,
183182
memory_start_position,
184183
memory_size,
185-
init_code_gas,
186184
)
187185

188186
# PROGRAM COUNTER
@@ -235,7 +233,6 @@ def create2(evm: Evm) -> None:
235233
contract_address,
236234
memory_start_position,
237235
memory_size,
238-
init_code_gas,
239236
)
240237

241238
# PROGRAM COUNTER

src/ethereum/fork_criteria.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from typing import Final, Literal, SupportsInt, Tuple
3030

3131
from ethereum_types.numeric import U256, Uint
32+
from typing_extensions import override
3233

3334

3435
@functools.total_ordering
@@ -130,6 +131,7 @@ def __init__(self, block_number: SupportsInt):
130131
self._internal = (ForkCriteria.BLOCK_NUMBER, int(block_number))
131132
self.block_number = Uint(int(block_number))
132133

134+
@override
133135
def check(self, block_number: Uint, timestamp: U256) -> bool:
134136
"""
135137
Check whether the block number has been reached.
@@ -162,6 +164,7 @@ def __init__(self, timestamp: SupportsInt):
162164
self._internal = (ForkCriteria.TIMESTAMP, int(timestamp))
163165
self.timestamp = U256(timestamp)
164166

167+
@override
165168
def check(self, block_number: Uint, timestamp: U256) -> bool:
166169
"""
167170
Check whether the timestamp has been reached.
@@ -188,6 +191,7 @@ class Unscheduled(ForkCriteria):
188191
def __init__(self) -> None:
189192
self._internal = (ForkCriteria.UNSCHEDULED, 0)
190193

194+
@override
191195
def check(self, block_number: Uint, timestamp: U256) -> Literal[False]:
192196
"""
193197
Unscheduled forks never occur; always returns `False`.

src/ethereum/prague/vm/instructions/system.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def generic_create(
6666
contract_address: Address,
6767
memory_start_position: U256,
6868
memory_size: U256,
69-
init_code_gas: Uint,
7069
) -> None:
7170
"""
7271
Core logic used by the `CREATE*` family of opcodes.
@@ -184,7 +183,6 @@ def create(evm: Evm) -> None:
184183
contract_address,
185184
memory_start_position,
186185
memory_size,
187-
init_code_gas,
188186
)
189187

190188
# PROGRAM COUNTER
@@ -237,7 +235,6 @@ def create2(evm: Evm) -> None:
237235
contract_address,
238236
memory_start_position,
239237
memory_size,
240-
init_code_gas,
241238
)
242239

243240
# PROGRAM COUNTER

src/ethereum/shanghai/vm/instructions/system.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def generic_create(
6464
contract_address: Address,
6565
memory_start_position: U256,
6666
memory_size: U256,
67-
init_code_gas: Uint,
6867
) -> None:
6968
"""
7069
Core logic used by the `CREATE*` family of opcodes.
@@ -181,7 +180,6 @@ def create(evm: Evm) -> None:
181180
contract_address,
182181
memory_start_position,
183182
memory_size,
184-
init_code_gas,
185183
)
186184

187185
# PROGRAM COUNTER
@@ -234,7 +232,6 @@ def create2(evm: Evm) -> None:
234232
contract_address,
235233
memory_start_position,
236234
memory_size,
237-
init_code_gas,
238235
)
239236

240237
# PROGRAM COUNTER

src/ethereum/trace.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ class GasAndRefund:
170170

171171

172172
def discard_evm_trace(
173-
evm: object,
174-
event: TraceEvent,
175-
trace_memory: bool = False,
176-
trace_stack: bool = True,
177-
trace_return_data: bool = False,
173+
evm: object, # noqa: U100
174+
event: TraceEvent, # noqa: U100
175+
trace_memory: bool = False, # noqa: U100
176+
trace_stack: bool = True, # noqa: U100
177+
trace_return_data: bool = False, # noqa: U100
178178
) -> None:
179179
"""
180180
An [`EvmTracer`] that discards all events.
@@ -200,9 +200,9 @@ def __call__(
200200
evm: object,
201201
event: TraceEvent,
202202
/,
203-
trace_memory: bool = False,
204-
trace_stack: bool = True,
205-
trace_return_data: bool = False,
203+
trace_memory: bool = False, # noqa: U100
204+
trace_stack: bool = True, # noqa: U100
205+
trace_return_data: bool = False, # noqa: U100
206206
) -> None:
207207
"""
208208
Call `self` as a function, recording a trace event.

src/ethereum_spec_tools/docc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from fladrif.treediff import Adapter, Operation, TreeMatcher
5454
from mistletoe import block_token as blocks # type: ignore
5555
from mistletoe import span_token as spans
56-
from typing_extensions import assert_never
56+
from typing_extensions import assert_never, override
5757

5858
from .forks import Hardfork
5959

@@ -775,6 +775,7 @@ def enter(self, node: Node) -> Visit:
775775
parent.replace_child(flex, new_node)
776776
return Visit.TraverseChildren
777777

778+
@override
778779
def exit(self, node: Node) -> None:
779780
self._stack.pop()
780781

@@ -908,11 +909,13 @@ def insert(self, afters: Sequence[Node]) -> None:
908909
)
909910
)
910911

912+
@override
911913
def equal(self, before: Sequence[Node], after: Sequence[Node]) -> None:
912914
parent = self.stack[-1]
913915
for node in after:
914916
parent.add(node)
915917

918+
@override
916919
def descend(self, before: Node, after: Node) -> None:
917920
parent = self.stack[-1]
918921
node = _DoccApply.FlexNode(after)
@@ -1000,12 +1003,13 @@ def enter(self, node: Node) -> Visit:
10001003

10011004
return Visit.SkipChildren
10021005

1006+
@override
10031007
def exit(self, node: Node) -> None:
10041008
self._stack.pop()
10051009

10061010

10071011
def render_diff(
1008-
context: object,
1012+
context: object, # noqa: U100
10091013
parent: object,
10101014
diff: object,
10111015
) -> html.RenderResult:

src/ethereum_spec_tools/evm_tools/daemon.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from typing import Any, Tuple, Union
1515
from urllib.parse import parse_qs, urlparse
1616

17+
from typing_extensions import override
18+
1719

1820
def daemon_arguments(subparsers: argparse._SubParsersAction) -> None:
1921
"""
@@ -30,6 +32,7 @@ def daemon_arguments(subparsers: argparse._SubParsersAction) -> None:
3032

3133

3234
class _EvmToolHandler(BaseHTTPRequestHandler):
35+
@override
3336
def log_request(
3437
self, code: int | str = "-", size: int | str = "-"
3538
) -> None:

src/ethereum_spec_tools/lint/lints/glacier_forks_hygiene.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import sys
88
from typing import Dict, List, Sequence
99

10+
from typing_extensions import override
11+
1012
from ethereum_spec_tools.forks import Hardfork
1113
from ethereum_spec_tools.lint import (
1214
Diagnostic,
@@ -193,12 +195,14 @@ def visit_Module(self, module: ast.Module) -> None:
193195
for item in module.__dict__["body"]:
194196
self.visit(item)
195197

198+
@override
196199
def visit_Import(self, import_: ast.Import) -> None:
197200
"""
198201
Visit an Import
199202
"""
200203
pass
201204

205+
@override
202206
def visit_ImportFrom(self, import_from: ast.ImportFrom) -> None:
203207
"""
204208
Visit an Import From

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def git_clone_fixtures(url: str, commit_hash: str, location: str) -> None:
114114
submodule.update(init=True, recursive=True)
115115

116116

117-
def pytest_sessionstart(session: Session) -> None:
117+
def pytest_sessionstart(session: Session) -> None: # noqa: U100
118118
for _, props in TEST_FIXTURES.items():
119119
fixture_path = props["fixture_path"]
120120

0 commit comments

Comments
 (0)