Skip to content

Commit b5a2ba4

Browse files
committed
lint: silence messages on "improper" f-string formatting.
The messages silenced in this commit are all: On Python 3 '{}'.format(b'abc') produces "b'abc'"; use !r if this is a desired behavior Sadly, `mypy` doesn't say which particular fields are problematic; I've tried my best to single them out - hopefully, nothing extraneous got in.
1 parent 3513f69 commit b5a2ba4

File tree

10 files changed

+19
-19
lines changed

10 files changed

+19
-19
lines changed

eth/chains/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ def from_genesis(cls,
225225
# the computed state from the initialized state database.
226226
raise ValidationError(
227227
"The provided genesis state root does not match the computed "
228-
f"genesis state root. Got {state.state_root}. "
229-
f"Expected {genesis_params['state_root']}"
228+
f"genesis state root. Got {state.state_root!r}. "
229+
f"Expected {genesis_params['state_root']!r}"
230230
)
231231

232232
genesis_header = BlockHeader(**genesis_params)
@@ -419,8 +419,8 @@ def import_block(self,
419419
except HeaderNotFound:
420420
raise ValidationError(
421421
f"Attempt to import block #{block.number}. "
422-
f"Cannot import block {block.hash} before importing "
423-
f"its parent block at {block.header.parent_hash}"
422+
f"Cannot import block {block.hash!r} before importing "
423+
f"its parent block at {block.header.parent_hash!r}"
424424
)
425425

426426
base_header_for_import = self.create_header_from_parent(parent_header)

eth/consensus/clique/_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ def validate_header_integrity(header: BlockHeaderAPI, epoch_length: int) -> None
139139
)
140140

141141
if header.nonce != NONCE_AUTH and header.nonce != NONCE_DROP:
142-
raise ValidationError(f"Invalid nonce: {header.nonce}")
142+
raise ValidationError(f"Invalid nonce: {header.nonce!r}")
143143

144144
if at_checkpoint and header.nonce != NONCE_DROP:
145-
raise ValidationError(f"Invalid checkpoint nonce: {header.nonce}")
145+
raise ValidationError(f"Invalid checkpoint nonce: {header.nonce!r}")
146146

147147
if len(header.extra_data) < VANITY_LENGTH:
148148
raise ValidationError("Missing vanity bytes in extra data")
@@ -159,7 +159,7 @@ def validate_header_integrity(header: BlockHeaderAPI, epoch_length: int) -> None
159159
raise ValidationError("Checkpoint header must contain list of signers")
160160

161161
if header.mix_hash != ZERO_HASH32:
162-
raise ValidationError(f"Invalid mix hash: {header.mix_hash}")
162+
raise ValidationError(f"Invalid mix hash: {header.mix_hash!r}")
163163

164164
if header.uncles_hash != EMPTY_UNCLE_HASH:
165165
raise ValidationError(f"Invalid uncle hash: {header.uncle_hash}")

eth/consensus/clique/datatypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def validate_for(self,
4646
if not signer_is_kicked and not signer_is_nominated:
4747
raise ValidationError(
4848
"Must either kick an existing signer or nominate a new signer"
49-
f"Subject: {subject} Current signers: {signers}"
49+
f"Subject: {subject!r} Current signers: {signers}"
5050
)
5151

5252

eth/consensus/clique/snapshot_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,16 @@ def get_snapshot(self, block_number: int, block_hash: Hash32) -> Snapshot:
220220
# Otherwise, we can retrieve it on the fly
221221
header = self._chain_db.get_block_header_by_hash(block_hash)
222222
except HeaderNotFound:
223-
raise SnapshotNotFound(f"Can not get snapshot for {block_hash} at {block_number}")
223+
raise SnapshotNotFound(f"Can not get snapshot for {block_hash!r} at {block_number}")
224224
else:
225225
if header.block_number != block_number:
226226
raise SnapshotNotFound(
227-
f"Can not get snapshot for {block_hash} at {block_number}"
227+
f"Can not get snapshot for {block_hash!r} at {block_number}"
228228
)
229229
else:
230230
return self._create_snapshot_from_checkpoint_header(header)
231231

232-
raise SnapshotNotFound(f"Can not get snapshot for {block_hash} at {block_number}")
232+
raise SnapshotNotFound(f"Can not get snapshot for {block_hash!r} at {block_number}")
233233

234234
def add_snapshot(self, mutable_snapshot: MutableSnapshot) -> Snapshot:
235235
"""
@@ -256,7 +256,7 @@ def get_snapshot_from_db(self, block_hash: Hash32) -> Snapshot:
256256
encoded_key = self._chain_db.db[key]
257257
except KeyError as e:
258258
raise SnapshotNotFound(
259-
f"Can not get on-disk snapshot for {block_hash}"
259+
f"Can not get on-disk snapshot for {block_hash!r}"
260260
)
261261
else:
262262
return decode_snapshot(encoded_key)

eth/db/chain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def get_block_uncles(self, uncles_hash: Hash32) -> Tuple[BlockHeaderAPI, ...]:
8484
encoded_uncles = self.db[uncles_hash]
8585
except KeyError:
8686
raise HeaderNotFound(
87-
f"No uncles found for hash {uncles_hash}"
87+
f"No uncles found for hash {uncles_hash!r}"
8888
)
8989
else:
9090
return tuple(rlp.decode(encoded_uncles, sedes=rlp.sedes.CountableList(BlockHeader)))

eth/db/header.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def _set_as_canonical_chain_head(
254254
header = cls._get_block_header_by_hash(db, block_hash)
255255
except HeaderNotFound:
256256
raise ValueError(
257-
f"Cannot use unknown block hash as canonical head: {block_hash}"
257+
f"Cannot use unknown block hash as canonical head: {block_hash!r}"
258258
)
259259

260260
new_canonical_headers = tuple(reversed(

eth/tools/fixtures/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ def verify_state(expected_state: AccountState, state: StateAPI) -> None:
7676
if field == 'balance':
7777
error_messages.append(
7878
f"{to_normalized_address(account)}(balance) | "
79-
f"Actual: {actual_value} | Expected: {expected_value} | "
79+
f"Actual: {actual_value!r} | Expected: {expected_value!r} | "
8080
f"Delta: {cast(int, actual_value) - cast(int, expected_value)}"
8181
)
8282
else:
8383
error_messages.append(
8484
f"{to_normalized_address(account)}({field}) | "
85-
f"Actual: {actual_value} | Expected: {expected_value}"
85+
f"Actual: {actual_value!r} | Expected: {expected_value!r}"
8686
)
8787
raise AssertionError(
8888
f"State DB did not match expected state on {len(error_messages)} values:{new_line}"

eth/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def validate_lt(value: int, maximum: int, title: str="Value") -> None:
111111
def validate_canonical_address(value: Address, title: str="Value") -> None:
112112
if not isinstance(value, bytes) or not len(value) == 20:
113113
raise ValidationError(
114-
f"{title} {value} is not a valid canonical address"
114+
f"{title} {value!r} is not a valid canonical address"
115115
)
116116

117117

eth/vm/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def validate_block(self, block: BlockAPI) -> None:
502502
if tx_root_hash != block.header.transaction_root:
503503
raise ValidationError(
504504
f"Block's transaction_root ({block.header.transaction_root}) "
505-
f"does not match expected value: {tx_root_hash}"
505+
f"does not match expected value: {tx_root_hash!r}"
506506
)
507507

508508
if len(block.uncles) > MAX_UNCLES:

eth/vm/forks/frontier/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def validate_frontier_transaction(state: StateAPI,
1717

1818
if sender_balance < gas_cost:
1919
raise ValidationError(
20-
f"Sender {transaction.sender} cannot afford txn gas "
20+
f"Sender {transaction.sender!r} cannot afford txn gas "
2121
f"{gas_cost} with account balance {sender_balance}"
2222
)
2323

0 commit comments

Comments
 (0)