Skip to content

Commit 4ac7a9b

Browse files
gurukamathSamWilsn
andauthored
chore(tooling): Update static checks (#1428)
* add ruff format * extend checks to tests * remove exclude dirs from ruff config * add D space rules to ruff * stop ignoring D200 in ruff * stop ignoring D410 in ruff * stop ignoring D411 in ruff * stop ignoring D412 in ruff * stop ignoring D413 in ruff * stop ignoring D414 in ruff * stop ignoring D416 in ruff * stop ignoring E203 in ruff * tests follow the same rules as other code * tests stop ignoring D103 * tests stop ignoring D104 * tests stop ignoring E501 * clean up ruff config * stop ignoring D400 in ruff * stop ignoring D415 * Revert "stop ignoring D200 in ruff" * enable C4 * Apply suggestions from code review Co-authored-by: Sam Wilson <[email protected]> --------- Co-authored-by: Sam Wilson <[email protected]>
1 parent 5ddb904 commit 4ac7a9b

File tree

787 files changed

+3739
-1982
lines changed

Some content is hidden

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

787 files changed

+3739
-1982
lines changed

pyproject.toml

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -427,19 +427,6 @@ exclude = ["tests/fixtures/", "eest_tests/"]
427427
ignore_names = ["pytest_*"]
428428

429429
[tool.ruff]
430-
extend-exclude = [
431-
".cache/",
432-
".git/",
433-
".pytest_cache/",
434-
".ruff_cache/",
435-
".tox/",
436-
".venv/",
437-
".vscode/",
438-
"tests/fixtures/*",
439-
"tests/json_infra/fixtures/*",
440-
"eest_tests/*",
441-
"vulture_whitelist.py",
442-
]
443430
line-length = 79
444431

445432
[tool.ruff.lint]
@@ -451,6 +438,8 @@ select = [
451438
"I", # isort
452439
"A", # flake8-builtins
453440
"N", # pep8-naming
441+
"D", # pydocstyle
442+
"C4", # flake8-comprehensions
454443
"ARG", # flake8-unused-arguments
455444
]
456445
fixable = [
@@ -463,34 +452,17 @@ fixable = [
463452
]
464453
ignore = [
465454
# Common to STEEL
466-
"D205", # Missing blank line after summary
467-
"D203", # 1 blank line required before class docstring
468-
"D212", # Multi-line docstring summary should start at the first line
469-
"D415", # First line should end with a ".", "?", or "!"
470-
471-
# Specific to EELS
455+
"C401", # Unnecessary generator set
456+
"C408", # Unnecessary collection call
472457
"D107", # Missing docstring in __init__
473458
"D200", # One-line docstring should fit on one line with quotes
474-
"D205", # 1 blank line required between summary and description
475-
"D400", # First line should end with a period
459+
"D203", # 1 blank line required before class docstring
460+
"D205", # Missing blank line after summary
461+
"D212", # Multi-line docstring summary should start at the first line
476462
"D401", # First line should be in imperative mood ("Do", not "Does")
477-
"D410", # Missing blank line after last section (Args, Returns, Raises)
478-
"D411", # Missing blank line before last section
479-
"D412", # No blank lines between sections
480-
"D413", # Missing blank line after last section (same as 410)
481-
"D414", # Section should end with a period
482-
"D416", # Section names should be in the correct order
483-
"E203", # Whitespace before ':'
484463
]
485464

486465
[tool.ruff.lint.per-file-ignores]
487-
"tests/*" = [
488-
"D100", # Missing docstring in public module
489-
"D101", # Missing docstring in public class
490-
"D103", # Missing docstring in public function
491-
"D104", # Missing docstring in public package
492-
"E501", # Line too long
493-
]
494466
"src/ethereum_spec_tools/evm_tools/loaders/fork_loader.py" = [
495467
"N802" # Property names do not need to be lowercase
496468
]
@@ -508,10 +480,6 @@ ignore = [
508480
"N815" # The traces must use camel case in JSON property names
509481
]
510482

511-
[tool.ruff.lint.mccabe]
512-
# Set the maximum allowed cyclomatic complexity. C901 default is 10.
513-
max-complexity = 7
514-
515483
[tool.codespell]
516484
builtin = "clear,code,usage" # Built-in dictionaries to use
517485
skip = [ # Don't check these files/folders

src/ethereum/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
2+
Ethereum base package.
3+
24
### Introduction
35
46
Seeing as internet connections have been vastly expanding across the
@@ -16,6 +18,7 @@
1618
This package contains a reference implementation, written as simply as
1719
possible, to aid in defining the behavior of Ethereum clients.
1820
"""
21+
1922
import sys
2023

2124
__version__ = "2.18.0rc2"

src/ethereum/crypto/blake2.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"""
2-
The Blake2 Implementation
3-
^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
"""
1+
"""The Blake2 Implementation."""
2+
53
import struct
64
from dataclasses import dataclass
75
from typing import Final, List, Tuple
@@ -21,6 +19,7 @@ def spit_le_to_uint(data: bytes, start: int, num_words: int) -> List[Uint]:
2119
Position to start the extraction
2220
num_words:
2321
The number of words to be extracted
22+
2423
"""
2524
words = []
2625
for i in range(num_words):
@@ -61,31 +60,31 @@ def max_word(self) -> Uint:
6160
def w_R1(self) -> Uint:
6261
"""
6362
(w - R1) value for a given Blake2 flavor.
64-
Used in the function G
63+
Used in the function G.
6564
"""
6665
return self.w - self.R1
6766

6867
@property
6968
def w_R2(self) -> Uint:
7069
"""
7170
(w - R2) value for a given Blake2 flavor.
72-
Used in the function G
71+
Used in the function G.
7372
"""
7473
return self.w - self.R2
7574

7675
@property
7776
def w_R3(self) -> Uint:
7877
"""
7978
(w - R3) value for a given Blake2 flavor.
80-
Used in the function G
79+
Used in the function G.
8180
"""
8281
return self.w - self.R3
8382

8483
@property
8584
def w_R4(self) -> Uint:
8685
"""
8786
(w - R4) value for a given Blake2 flavor.
88-
Used in the function G
87+
Used in the function G.
8988
"""
9089
return self.w - self.R4
9190

@@ -140,6 +139,7 @@ def get_blake2_parameters(self, data: bytes) -> Tuple:
140139
----------
141140
data :
142141
The bytes data that has been passed in the message.
142+
143143
"""
144144
rounds = Uint.from_be_bytes(data[:4])
145145
h = spit_le_to_uint(data, 4, 8)
@@ -153,8 +153,11 @@ def G(
153153
self, v: List, a: Uint, b: Uint, c: Uint, d: Uint, x: Uint, y: Uint
154154
) -> List:
155155
"""
156-
The mixing function used in Blake2
157-
https://datatracker.ietf.org/doc/html/rfc7693#section-3.1
156+
The mixing function used in Blake2.
157+
158+
See [RFC 7693] for more details.
159+
160+
[RFC 7693]: https://datatracker.ietf.org/doc/html/rfc7693#section-3.1
158161
159162
Parameters
160163
----------
@@ -164,6 +167,7 @@ def G(
164167
Indexes within v of the words to be mixed.
165168
x, y :
166169
The two input words for the mixing.
170+
167171
"""
168172
v[a] = (v[a] + v[b] + x) % self.max_word
169173
v[d] = ((v[d] ^ v[a]) >> self.R1) ^ (
@@ -197,8 +201,7 @@ def compress(
197201
f: bool,
198202
) -> bytes:
199203
"""
200-
'F Compression' from section 3.2 of RFC 7693:
201-
https://tools.ietf.org/html/rfc7693#section-3.2
204+
'F Compression' from section 3.2 of RFC 7693.
202205
203206
Parameters
204207
----------
@@ -212,6 +215,7 @@ def compress(
212215
Offset counters. 2 unsigned 64-bit little-endian words
213216
f:
214217
The final block indicator flag. An 8-bit word
218+
215219
"""
216220
# Initialize local work vector v[0..15]
217221
v = [Uint(0)] * 16

src/ethereum/crypto/elliptic_curve.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
"""
2-
Elliptic Curves
3-
^^^^^^^^^^^^^^^
4-
"""
1+
"""Elliptic Curves."""
52

63
import coincurve
74
from Crypto.Util.asn1 import DerSequence
@@ -45,6 +42,7 @@ def secp256k1_recover(r: U256, s: U256, v: U256, msg_hash: Hash32) -> Bytes:
4542
-------
4643
public_key : `ethereum.base_types.Bytes`
4744
Recovered public key.
45+
4846
"""
4947
is_square = pow(
5048
pow(r, U256(3), SECP256K1P) + SECP256K1B,
@@ -114,8 +112,8 @@ def secp256r1_verify(
114112
115113
Raises
116114
------
117-
118115
Raises an `InvalidSignatureError` if the signature is not valid.
116+
119117
"""
120118
# Convert U256 to regular integers for DerSequence
121119
r_int = int(r)
@@ -152,6 +150,7 @@ def is_on_curve_secp256r1(x: U256, y: U256) -> bool:
152150
-------
153151
bool
154152
True if the point is on the curve, False otherwise
153+
155154
"""
156155
# Convert U256 to int for calculations
157156
x_int = int(x)

src/ethereum/crypto/hash.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
2-
Cryptographic Hash Functions
3-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2+
Cryptographic Hash Functions.
43
54
.. contents:: Table of Contents
65
:backlinks: none
@@ -32,6 +31,7 @@ def keccak256(buffer: Bytes | bytearray) -> Hash32:
3231
-------
3332
hash : `ethereum.base_types.Hash32`
3433
Output of the hash function.
34+
3535
"""
3636
k = keccak.new(digest_bits=256)
3737
return Hash32(k.update(buffer).digest())
@@ -50,6 +50,7 @@ def keccak512(buffer: Bytes | bytearray) -> Hash64:
5050
-------
5151
hash : `ethereum.base_types.Hash32`
5252
Output of the hash function.
53+
5354
"""
5455
k = keccak.new(digest_bits=512)
5556
return Hash64(k.update(buffer).digest())

src/ethereum/crypto/kzg.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"""
2-
The KZG Implementation
3-
^^^^^^^^^^^^^^^^^^^^^^
4-
"""
1+
"""The KZG Implementation."""
2+
53
from hashlib import sha256
64
from typing import Tuple
75

@@ -36,7 +34,7 @@ class KZGCommitment(Bytes48):
3634

3735

3836
class KZGProof(Bytes48):
39-
"""KZG proof"""
37+
"""KZG proof."""
4038

4139
pass
4240

src/ethereum/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55

6-
class EthereumException(Exception): # noqa N818
6+
class EthereumException(Exception): # noqa N818
77
"""
88
Base class for all exceptions _expected_ to be thrown during normal
99
operation.

src/ethereum/forks/arrow_glacier/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
[js]: https://github.com/ethereumjs/ethereumjs-monorepo/releases/tag/%40ethereumjs%2Fvm%405.6.0
2727
[Geth 1.10.12]: https://github.com/ethereum/go-ethereum/releases/tag/v1.10.12
2828
[nm]: https://github.com/NethermindEth/nethermind/releases/tag/1.11.7
29-
""" # noqa: E501
29+
""" # noqa: E501
3030

3131
from ethereum.fork_criteria import ByBlockNumber
3232

src/ethereum/forks/arrow_glacier/blocks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
history of all state transitions that have happened since the genesis of the
99
chain.
1010
"""
11+
1112
from dataclasses import dataclass
1213
from typing import Tuple
1314

src/ethereum/forks/arrow_glacier/bloom.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
2-
Ethereum Logs Bloom
3-
^^^^^^^^^^^^^^^^^^^
2+
Ethereum Logs Bloom.
43
54
.. contents:: Table of Contents
65
:backlinks: none
@@ -41,6 +40,7 @@ def add_to_bloom(bloom: bytearray, bloom_entry: Bytes) -> None:
4140
The bloom filter.
4241
bloom_entry :
4342
An entry which is to be added to bloom filter.
43+
4444
"""
4545
hashed = keccak256(bloom_entry)
4646

@@ -75,6 +75,7 @@ def logs_bloom(logs: Tuple[Log, ...]) -> Bloom:
7575
logs_bloom : `Bloom`
7676
The logs bloom obtained which is 256 bytes with some bits set as per
7777
the caller address and the log topics.
78+
7879
"""
7980
bloom: bytearray = bytearray(b"\x00" * 256)
8081

0 commit comments

Comments
 (0)