Skip to content

Commit c14e9c9

Browse files
authored
fix(tools): fix remaining lint checks after large ruff refactor (ethereum#2050)
1 parent 77c2b9c commit c14e9c9

7 files changed

Lines changed: 75 additions & 65 deletions

File tree

packages/testing/src/execution_testing/fixtures/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def fixture_format_discriminator(v: Any) -> str | None:
3333
info_dict = v.info
3434
if info_dict is None:
3535
raise ValueError(
36-
f"Fixture does not have an info field, cannot determine fixture format: {v}"
36+
"Fixture does not have an info field, "
37+
f"cannot determine fixture format: {v}"
3738
)
3839
fixture_format = info_dict.get("fixture-format")
3940
if not fixture_format:

packages/testing/src/execution_testing/fixtures/blockchain.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ def validate_post_state_fields(self: Any) -> Any:
9797

9898
if field1_value is None and field2_value is None:
9999
raise ValueError(
100-
f"Either {field1_name} or {field2_name} must be provided."
100+
f"Either {field1_name} or {field2_name} "
101+
"must be provided."
101102
)
102103
if field1_value is not None and field2_value is not None:
103104
raise ValueError(
104-
f"Only one of {field1_name} or {field2_name} must be provided."
105+
f"Only one of {field1_name} or {field2_name} "
106+
"must be provided."
105107
)
106108
return self
107109

@@ -145,8 +147,8 @@ class FixtureHeader(CamelModel):
145147
We combine the `Environment` and `Result` contents to create this model.
146148
"""
147149

148-
# Allow extra fields: FixtureHeader is constructed from merged Result and
149-
# Environment data via model_dump(), which includes fields not in this model.
150+
# Allow extra fields: FixtureHeader is constructed from merged Result
151+
# and Environment data via model_dump(), which has extra fields.
150152
model_config = CamelModel.model_config | {"extra": "ignore"}
151153

152154
parent_hash: Hash = Hash(0)
@@ -286,42 +288,51 @@ def get_default_from_annotation(
286288
timestamp: int = 0,
287289
) -> Any:
288290
"""
289-
Get appropriate default value for a header field based on its type hint.
291+
Get default value for a header field based on its type hint.
290292
291293
This method handles:
292-
1. Fork requirement checking - only returns a default if the fork requires the field
294+
1. Fork requirement checking - only returns a default if the fork
295+
requires the field
293296
2. Model-defined defaults - uses the field's default value if available
294297
3. Type-based defaults - constructs defaults based on the field type
295298
296299
Args:
297300
fork: Fork to check requirements against
298301
field_name: Name of the field
299302
field_hint: Type annotation of the field
300-
block_number: Block number for fork requirement checking (default: 0)
303+
block_number: Block number for fork requirement checking
304+
(default: 0)
301305
timestamp: Timestamp for fork requirement checking (default: 0)
302306
303307
Returns:
304308
Default value appropriate for the field type, or None if
305309
the field is not required by the fork
306310
307311
Raises:
308-
TypeError: If the field type is not supported and no default value
309-
is defined in the model. This indicates that support for the type
310-
needs to be added or an explicit default must be provided.
312+
TypeError: If the field type is not supported and no default
313+
value is defined in the model. This indicates that support
314+
for the type needs to be added or an explicit default must
315+
be provided.
316+
311317
"""
312318
# Check if this field has a HeaderForkRequirement annotation
313319
header_fork_requirement = HeaderForkRequirement.get_from_annotation(
314320
field_hint
315321
)
316322
if header_fork_requirement is not None:
317323
# Only provide a default if the fork requires this field
318-
if not header_fork_requirement.required(fork, block_number, timestamp):
324+
if not header_fork_requirement.required(
325+
fork, block_number, timestamp
326+
):
319327
return None
320328

321329
# Check if the field has a default value defined in the model
322330
if field_name in cls.model_fields:
323331
field_info = cls.model_fields[field_name]
324-
if field_info.default is not None and field_info.default is not PydanticUndefined:
332+
if (
333+
field_info.default is not None
334+
and field_info.default is not PydanticUndefined
335+
):
325336
return field_info.default
326337
if field_info.default_factory is not None:
327338
return field_info.default_factory() # type: ignore[call-arg]
@@ -339,11 +350,11 @@ def get_default_from_annotation(
339350
elif actual_type == Bytes:
340351
return Bytes(b"")
341352
else:
342-
# Unsupported type - raise an error to catch this during development
353+
# Unsupported type - raise error to catch this during development
343354
raise TypeError(
344355
f"Cannot generate default value for field '{field_name}' "
345356
f"with unsupported type '{actual_type}'. "
346-
f"Add support for this type or provide a default value explicitly."
357+
"Add support for this type or provide a default explicitly."
347358
)
348359

349360
@classmethod
@@ -501,7 +512,8 @@ def from_fixture_header(
501512
):
502513
if block_access_list is None:
503514
raise ValueError(
504-
f"`block_access_list` is required in engine `ExecutionPayload` for >={fork}."
515+
"`block_access_list` is required in engine "
516+
f"`ExecutionPayload` for >={fork}."
505517
)
506518

507519
execution_payload = FixtureExecutionPayload.from_fixture_header(
@@ -609,8 +621,9 @@ class FixtureBlockBase(CamelModel):
609621
@classmethod
610622
def strip_block_number_computed_field(cls, data: Any) -> Any:
611623
"""
612-
Strip the block_number computed field which gets included in model_dump()
613-
but is not a valid input field.
624+
Strip the block_number computed field included in model_dump().
625+
626+
This field is not a valid input field.
614627
"""
615628
if isinstance(data, dict):
616629
data.pop("blocknumber", None)
@@ -785,7 +798,7 @@ class BlockchainEngineXFixture(BlockchainEngineFixtureCommon):
785798
"""
786799

787800
# Allow extra fields: BlockchainEngineXFixture is constructed from shared
788-
# fixture_data that includes fields for other fixture formats (e.g. genesis).
801+
# fixture_data that has fields for other fixture formats (e.g. genesis).
789802
model_config = CamelModel.model_config | {"extra": "ignore"}
790803

791804
format_name: ClassVar[str] = "blockchain_test_engine_x"
@@ -824,7 +837,8 @@ class BlockchainEngineSyncFixture(BlockchainEngineFixture):
824837

825838
format_name: ClassVar[str] = "blockchain_test_sync"
826839
description: ClassVar[str] = (
827-
"Tests that generate a blockchain test fixture for Engine API testing with client sync."
840+
"Tests that generate a blockchain test fixture for Engine API "
841+
"testing with client sync."
828842
)
829843
sync_payload: FixtureEngineNewPayload | None = None
830844

packages/testing/src/execution_testing/fixtures/collector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def get_dump_dir_path(
8484
str(test_module_relative_dir).replace(os.sep, "__")
8585
)
8686
test_name, test_parameter_string = self.get_name_and_parameters()
87-
flat_path = f"{str(test_module_relative_dir).replace(os.sep, '__')}__{test_name}"
87+
dir_str = str(test_module_relative_dir).replace(os.sep, "__")
88+
flat_path = f"{dir_str}__{test_name}"
8889
if level == "test_function":
8990
return Path(base_dump_dir) / flat_path
9091
elif level == "test_parameter":

packages/testing/src/execution_testing/fixtures/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class FixtureAuthorizationTuple(
5252
"""Authorization tuple for fixture transactions."""
5353

5454
# Allow extra fields: FixtureAuthorizationTuple is constructed from
55-
# AuthorizationTuple via model_dump(), which includes fields not in this model.
55+
# AuthorizationTuple via model_dump(), which has extra fields.
5656
model_config = CamelModel.model_config | {"extra": "ignore"}
5757

5858
v: ZeroPaddedHexNumber = Field(

packages/testing/src/execution_testing/fixtures/pre_alloc_groups.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class ModelDumpCache:
178178
model_dump_mode: Literal["json", "python"]
179179
"""Mode of the model dump when `model_dump` is called."""
180180
model_dump_type: Literal["string", "dict"]
181-
"""Whether `model_dump_json` or `model_dump` was used to generate the data."""
181+
"""Whether `model_dump_json` or `model_dump` was used to generate data."""
182182
data: Any
183183

184184

@@ -197,7 +197,7 @@ class GroupPreAlloc(Alloc):
197197
_model_dump_cache: ModelDumpCache | None = PrivateAttr(None)
198198

199199
def state_root(self) -> Hash:
200-
"""On pre-alloc groups, which are normally very big, we always cache."""
200+
"""On pre-alloc groups, which are normally very big, always cache."""
201201
if self._cached_state_root is not None:
202202
return self._cached_state_root
203203
return super().state_root()
@@ -230,7 +230,7 @@ def model_dump( # type: ignore[override]
230230
return data
231231

232232
def model_dump_json(self, **kwargs: Any) -> str:
233-
"""Model dump the pre-allocation group in JSON string format, with caching."""
233+
"""Model dump the pre-allocation group in JSON string, with caching."""
234234
if (
235235
self._model_dump_cache is not None
236236
and self._model_dump_cache.model_dump_mode == "json"

0 commit comments

Comments
 (0)