Skip to content

Commit

Permalink
Disallow unused arguments (closes ethereum#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWilsn committed Jun 24, 2024
1 parent 656e3d2 commit 07f3496
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 57 deletions.
9 changes: 8 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ python_requires = >=3.10
install_requires =
pycryptodome>=3,<4
coincurve>=20,<21
typing_extensions>=4
typing_extensions>=4.4
eth2spec @ git+https://github.com/ethereum/consensus-specs.git@d302b35d40c72842d444ef2ea64344e3cb889804

[options.package_data]
Expand Down Expand Up @@ -168,6 +168,7 @@ lint =
flake8-bugbear==23.12.2
flake8-docstrings==1.7.0
flake8-spellcheck==0.28.0
flake8-unused-arguments==0.0.13

doc =
docc>=0.2.0,<0.3.0
Expand All @@ -181,6 +182,7 @@ optimized =
dictionaries=en_US,python,technical
docstring-convention = all
extend-ignore =
U101
E203
D107
D200
Expand All @@ -206,4 +208,9 @@ per-file-ignores =
src/ethereum/base_types.py:D105,SC100,SC200
tests/*:D100,D101,D103,D104,E501,SC100,SC200

unused-arguments-ignore-abstract-functions = true
unused-arguments-ignore-override-functions = true
unused-arguments-ignore-overload-functions = true
unused-arguments-ignore-dunder = true

# vim: set ft=dosini:
5 changes: 1 addition & 4 deletions src/ethereum/byzantium/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ def check_transaction(


def make_receipt(
tx: Transaction,
error: Optional[Exception],
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
Expand Down Expand Up @@ -480,9 +479,7 @@ def apply_body(
gas_used, logs, error = process_transaction(env, tx)
gas_available -= gas_used

receipt = make_receipt(
tx, error, (block_gas_limit - gas_available), logs
)
receipt = make_receipt(error, (block_gas_limit - gas_available), logs)

trie_set(
receipts_trie,
Expand Down
3 changes: 0 additions & 3 deletions src/ethereum/cancun/vm/instructions/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def generic_create(
contract_address: Address,
memory_start_position: U256,
memory_size: U256,
init_code_gas: Uint,
) -> None:
"""
Core logic used by the `CREATE*` family of opcodes.
Expand Down Expand Up @@ -171,7 +170,6 @@ def create(evm: Evm) -> None:
contract_address,
memory_start_position,
memory_size,
init_code_gas,
)

# PROGRAM COUNTER
Expand Down Expand Up @@ -224,7 +222,6 @@ def create2(evm: Evm) -> None:
contract_address,
memory_start_position,
memory_size,
init_code_gas,
)

# PROGRAM COUNTER
Expand Down
7 changes: 1 addition & 6 deletions src/ethereum/constantinople/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ def check_transaction(


def make_receipt(
tx: Transaction,
error: Optional[Exception],
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
Expand All @@ -345,8 +344,6 @@ def make_receipt(
Parameters
----------
tx :
The executed transaction.
error :
Error in the top level frame of the transaction, if any.
cumulative_gas_used :
Expand Down Expand Up @@ -480,9 +477,7 @@ def apply_body(
gas_used, logs, error = process_transaction(env, tx)
gas_available -= gas_used

receipt = make_receipt(
tx, error, (block_gas_limit - gas_available), logs
)
receipt = make_receipt(error, (block_gas_limit - gas_available), logs)

trie_set(
receipts_trie,
Expand Down
5 changes: 1 addition & 4 deletions src/ethereum/dao_fork/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ def check_transaction(


def make_receipt(
tx: Transaction,
post_state: Bytes32,
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
Expand All @@ -354,8 +353,6 @@ def make_receipt(
Parameters
----------
tx :
The executed transaction.
post_state :
The state root immediately after this transaction.
cumulative_gas_used :
Expand Down Expand Up @@ -487,7 +484,7 @@ def apply_body(
gas_available -= gas_used

receipt = make_receipt(
tx, state_root(state), (block_gas_limit - gas_available), logs
state_root(state), (block_gas_limit - gas_available), logs
)

trie_set(
Expand Down
5 changes: 5 additions & 0 deletions src/ethereum/fork_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from abc import ABC, abstractmethod
from typing import Final, Tuple

from typing_extensions import override


@functools.total_ordering
class ForkCriteria(ABC):
Expand Down Expand Up @@ -128,6 +130,7 @@ def __init__(self, block_number: int):
self._internal = (ForkCriteria.BLOCK_NUMBER, block_number)
self.block_number = block_number

@override
def check(self, block_number: int, timestamp: int) -> bool:
"""
Check whether the block number has been reached.
Expand Down Expand Up @@ -160,6 +163,7 @@ def __init__(self, timestamp: int):
self._internal = (ForkCriteria.TIMESTAMP, timestamp)
self.timestamp = timestamp

@override
def check(self, block_number: int, timestamp: int) -> bool:
"""
Check whether the timestamp has been reached.
Expand All @@ -186,6 +190,7 @@ class Unscheduled(ForkCriteria):
def __init__(self) -> None:
self._internal = (ForkCriteria.UNSCHEDULED, 0)

@override
def check(self, block_number: int, timestamp: int) -> bool:
"""
Unscheduled forks never occur; always returns `False`.
Expand Down
3 changes: 1 addition & 2 deletions src/ethereum/frontier/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ def check_transaction(


def make_receipt(
tx: Transaction,
post_state: Bytes32,
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
Expand Down Expand Up @@ -467,7 +466,7 @@ def apply_body(
gas_available -= gas_used

receipt = make_receipt(
tx, state_root(state), (block_gas_limit - gas_available), logs
state_root(state), (block_gas_limit - gas_available), logs
)

trie_set(
Expand Down
3 changes: 1 addition & 2 deletions src/ethereum/homestead/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ def check_transaction(


def make_receipt(
tx: Transaction,
post_state: Bytes32,
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
Expand Down Expand Up @@ -469,7 +468,7 @@ def apply_body(
gas_available -= gas_used

receipt = make_receipt(
tx, state_root(state), (block_gas_limit - gas_available), logs
state_root(state), (block_gas_limit - gas_available), logs
)

trie_set(
Expand Down
5 changes: 1 addition & 4 deletions src/ethereum/istanbul/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ def check_transaction(


def make_receipt(
tx: Transaction,
error: Optional[Exception],
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
Expand Down Expand Up @@ -481,9 +480,7 @@ def apply_body(
gas_used, logs, error = process_transaction(env, tx)
gas_available -= gas_used

receipt = make_receipt(
tx, error, (block_gas_limit - gas_available), logs
)
receipt = make_receipt(error, (block_gas_limit - gas_available), logs)

trie_set(
receipts_trie,
Expand Down
5 changes: 1 addition & 4 deletions src/ethereum/muir_glacier/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ def check_transaction(


def make_receipt(
tx: Transaction,
error: Optional[Exception],
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
Expand Down Expand Up @@ -481,9 +480,7 @@ def apply_body(
gas_used, logs, error = process_transaction(env, tx)
gas_available -= gas_used

receipt = make_receipt(
tx, error, (block_gas_limit - gas_available), logs
)
receipt = make_receipt(error, (block_gas_limit - gas_available), logs)

trie_set(
receipts_trie,
Expand Down
3 changes: 0 additions & 3 deletions src/ethereum/shanghai/vm/instructions/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def generic_create(
contract_address: Address,
memory_start_position: U256,
memory_size: U256,
init_code_gas: Uint,
) -> None:
"""
Core logic used by the `CREATE*` family of opcodes.
Expand Down Expand Up @@ -170,7 +169,6 @@ def create(evm: Evm) -> None:
contract_address,
memory_start_position,
memory_size,
init_code_gas,
)

# PROGRAM COUNTER
Expand Down Expand Up @@ -223,7 +221,6 @@ def create2(evm: Evm) -> None:
contract_address,
memory_start_position,
memory_size,
init_code_gas,
)

# PROGRAM COUNTER
Expand Down
5 changes: 1 addition & 4 deletions src/ethereum/spurious_dragon/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ def check_transaction(


def make_receipt(
tx: Transaction,
post_state: Bytes32,
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
Expand All @@ -341,8 +340,6 @@ def make_receipt(
Parameters
----------
tx :
The executed transaction.
post_state :
The state root immediately after this transaction.
cumulative_gas_used :
Expand Down Expand Up @@ -477,7 +474,7 @@ def apply_body(
gas_available -= gas_used

receipt = make_receipt(
tx, state_root(state), (block_gas_limit - gas_available), logs
state_root(state), (block_gas_limit - gas_available), logs
)

trie_set(
Expand Down
5 changes: 1 addition & 4 deletions src/ethereum/tangerine_whistle/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ def check_transaction(


def make_receipt(
tx: Transaction,
post_state: Bytes32,
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
Expand All @@ -336,8 +335,6 @@ def make_receipt(
Parameters
----------
tx :
The executed transaction.
post_state :
The state root immediately after this transaction.
cumulative_gas_used :
Expand Down Expand Up @@ -469,7 +466,7 @@ def apply_body(
gas_available -= gas_used

receipt = make_receipt(
tx, state_root(state), (block_gas_limit - gas_available), logs
state_root(state), (block_gas_limit - gas_available), logs
)

trie_set(
Expand Down
16 changes: 8 additions & 8 deletions src/ethereum/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ class GasAndRefund:


def discard_evm_trace(
evm: object,
event: TraceEvent,
trace_memory: bool = False,
trace_stack: bool = True,
trace_return_data: bool = False,
evm: object, # noqa: U100
event: TraceEvent, # noqa: U100
trace_memory: bool = False, # noqa: U100
trace_stack: bool = True, # noqa: U100
trace_return_data: bool = False, # noqa: U100
) -> None:
"""
An [`EvmTracer`] that discards all events.
Expand All @@ -196,9 +196,9 @@ def __call__(
evm: object,
event: TraceEvent,
/,
trace_memory: bool = False,
trace_stack: bool = True,
trace_return_data: bool = False,
trace_memory: bool = False, # noqa: U100
trace_stack: bool = True, # noqa: U100
trace_return_data: bool = False, # noqa: U100
) -> None:
"""
Call `self` as a function, recording a trace event.
Expand Down
8 changes: 6 additions & 2 deletions src/ethereum_spec_tools/docc.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from fladrif.treediff import Adapter, Operation, TreeMatcher
from mistletoe import block_token as blocks # type: ignore
from mistletoe import span_token as spans
from typing_extensions import assert_never
from typing_extensions import assert_never, override

from .forks import Hardfork

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

@override
def exit(self, node: Node) -> None:
self._stack.pop()

Expand Down Expand Up @@ -908,11 +909,13 @@ def insert(self, afters: Sequence[Node]) -> None:
)
)

@override
def equal(self, before: Sequence[Node], after: Sequence[Node]) -> None:
parent = self.stack[-1]
for node in after:
parent.add(node)

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

return Visit.SkipChildren

@override
def exit(self, node: Node) -> None:
self._stack.pop()


def render_diff(
context: object,
context: object, # noqa: U100
parent: object,
diff: object,
) -> html.RenderResult:
Expand Down
Loading

0 comments on commit 07f3496

Please sign in to comment.