Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions eth/_utils/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def configure(cls: Type[T],
continue
elif not hasattr(cls, key):
raise TypeError(
"The {0}.configure cannot set attributes that are not "
"already present on the base class. The attribute `{1}` was "
"not found on the base class `{2}`".format(cls.__name__, key, cls)
"The {}.configure cannot set attributes that are not "
"already present on the base class. The attribute `{}` was "
"not found on the base class `{}`".format(cls.__name__, key, cls)
)

# overrides that are for sub-properties of this class
Expand All @@ -110,10 +110,10 @@ def configure(cls: Type[T],

if not isinstance(sub_cls, type) or not issubclass(sub_cls, Configurable):
raise TypeError(
"Unable to configure property `{0}` on class `{1}`. The "
"Unable to configure property `{}` on class `{}`. The "
"property being configured must be a subclass of the "
"`Configurable` type. Instead got the following object "
"instance: {2}".format(
"instance: {}".format(
key,
repr(cls),
repr(sub_cls),
Expand Down
2 changes: 1 addition & 1 deletion eth/_utils/empty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Empty(object):
class Empty:
pass


Expand Down
8 changes: 4 additions & 4 deletions eth/_utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@


# No set literals because we support Python 2.6.
TRUE_VALUES = set((
TRUE_VALUES = {
True,
'True',
'true',
))
}


class empty(object):
class empty:
"""
We use this sentinel object, instead of None, as None is a plausible value
for a default in real Python code.
Expand All @@ -49,7 +49,7 @@ def get_env_value(name: str, required: bool=False, default: Any=empty) -> str:
value = os.environ[name]
except KeyError:
raise KeyError(
"Must set environment variable {0}".format(name)
f"Must set environment variable {name}"
)
else:
value = os.environ.get(name, default)
Expand Down
4 changes: 2 additions & 2 deletions eth/_utils/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def compute_gas_limit(parent_header: BlockHeader, gas_limit_floor: int) -> int:
if gas_limit_floor < GAS_LIMIT_MINIMUM:
raise ValueError(
"The `gas_limit_floor` value must be greater than the "
"GAS_LIMIT_MINIMUM. Got {0}. Must be greater than "
"{1}".format(gas_limit_floor, GAS_LIMIT_MINIMUM)
"GAS_LIMIT_MINIMUM. Got {}. Must be greater than "
"{}".format(gas_limit_floor, GAS_LIMIT_MINIMUM)
)

decay = parent_header.gas_limit // GAS_LIMIT_EMA_DENOMINATOR
Expand Down
4 changes: 2 additions & 2 deletions eth/_utils/module_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def import_string(dotted_path: str) -> ModuleType:
try:
return getattr(module, class_name)
except AttributeError:
msg = 'Module "%s" does not define a "%s" attribute/class' % (
msg = 'Module "{}" does not define a "{}" attribute/class'.format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could become an f-string, too?

module_path, class_name)
raise ImportError(msg)

Expand All @@ -48,7 +48,7 @@ def split_at_longest_importable_path(dotted_path: str) -> Tuple[str, str]:
operator.attrgetter(remainder)(module)
except AttributeError:
raise ImportError(
"Unable to derive appropriate import path for {0}".format(
"Unable to derive appropriate import path for {}".format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also become an f-string

dotted_path,
)
)
Expand Down
10 changes: 5 additions & 5 deletions eth/_utils/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
def int_to_bytes32(value: Union[int, bool]) -> Hash32:
if not isinstance(value, int) or isinstance(value, bool):
raise ValueError(
"Value must be an integer: Got: {0}".format(
"Value must be an integer: Got: {}".format(
type(value),
)
)
if value < 0:
raise ValueError(
"Value cannot be negative: Got: {0}".format(
"Value cannot be negative: Got: {}".format(
value,
)
)
if value > UINT_256_MAX:
raise ValueError(
"Value exeeds maximum UINT256 size. Got: {0}".format(
"Value exeeds maximum UINT256 size. Got: {}".format(
value,
)
)
Expand Down Expand Up @@ -112,13 +112,13 @@ def integer_squareroot(value: int) -> int:
"""
if not isinstance(value, int) or isinstance(value, bool):
raise ValueError(
"Value must be an integer: Got: {0}".format(
"Value must be an integer: Got: {}".format(
type(value),
)
)
if value < 0:
raise ValueError(
"Value cannot be negative: Got: {0}".format(
"Value cannot be negative: Got: {}".format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the above could become f-strings

value,
)
)
Expand Down
6 changes: 2 additions & 4 deletions eth/_utils/rlp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import rlp
from typing import (
Iterable,
Expand Down Expand Up @@ -34,7 +32,7 @@ def diff_rlp_object(left: BaseBlock,
sub_diff = diff_rlp_object(left_value, right_value)
for sub_field_name, sub_left_value, sub_right_value in sub_diff:
yield (
"{0}.{1}".format(field_name, sub_field_name),
f"{field_name}.{sub_field_name}",
sub_left_value,
sub_right_value,
)
Expand Down Expand Up @@ -83,7 +81,7 @@ def validate_rlp_equal(obj_a: BaseBlock,
"Mismatch between {obj_a_name} and {obj_b_name} on {0} fields:\n - {1}".format(
len(diff),
"\n - ".join(tuple(
"{0}:\n (actual) : {1}\n (expected): {2}".format(
"{}:\n (actual) : {}\n (expected): {}".format(
field_name.ljust(longest_field_name, ' '),
actual,
expected,
Expand Down
2 changes: 1 addition & 1 deletion eth/_utils/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def diff_state(
if actual_storage_value != expected_storage_value:
yield (
account,
'storage[{0}]'.format(slot),
f'storage[{slot}]',
actual_storage_value,
expected_storage_value,
)
2 changes: 1 addition & 1 deletion eth/_utils/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def validate_transaction_signature(transaction: BaseTransaction) -> None:
try:
public_key = signature.recover_public_key_from_msg(message)
except BadSignature as e:
raise ValidationError("Bad Signature: {0}".format(str(e)))
raise ValidationError("Bad Signature: {}".format(str(e)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also become an f-string


if not signature.verify_msg(message, public_key):
raise ValidationError("Invalid Signature")
Expand Down
22 changes: 10 additions & 12 deletions eth/chains/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import operator
import random
from typing import (
Expand Down Expand Up @@ -129,7 +127,7 @@ def get_vm_class_for_block_number(cls, block_number: BlockNumber) -> Type[Virtua
if block_number >= start_block:
return vm_class
else:
raise VMNotFound("No vm available for block #{0}".format(block_number))
raise VMNotFound(f"No vm available for block #{block_number}")

@classmethod
def get_vm_class(cls, header: BlockHeaderAPI) -> Type[VirtualMachineAPI]:
Expand Down Expand Up @@ -172,7 +170,7 @@ def validate_chain(
vm_class.validate_header(child, parent, check_seal=should_check_seal)
except ValidationError as exc:
raise ValidationError(
"%s is not a valid child of %s: %s" % (
"{} is not a valid child of {}: {}".format(
child,
parent,
exc,
Expand Down Expand Up @@ -247,7 +245,7 @@ def from_genesis(cls,
# the computed state from the initialized state database.
raise ValidationError(
"The provided genesis state root does not match the computed "
"genesis state root. Got {0}. Expected {1}".format(
"genesis state root. Got {}. Expected {}".format(
state.state_root,
genesis_params['state_root'],
)
Expand Down Expand Up @@ -609,11 +607,11 @@ def validate_gaslimit(self, header: BlockHeaderAPI) -> None:
low_bound, high_bound = compute_gas_limit_bounds(parent_header)
if header.gas_limit < low_bound:
raise ValidationError(
"The gas limit on block {0} is too low: {1}. It must be at least {2}".format(
"The gas limit on block {} is too low: {}. It must be at least {}".format(
encode_hex(header.hash), header.gas_limit, low_bound))
elif header.gas_limit > high_bound:
raise ValidationError(
"The gas limit on block {0} is too high: {1}. It must be at most {2}".format(
"The gas limit on block {} is too high: {}. It must be at most {}".format(
encode_hex(header.hash), header.gas_limit, high_bound))

def validate_uncles(self, block: BlockAPI) -> None:
Expand All @@ -639,7 +637,7 @@ def validate_uncles(self, block: BlockAPI) -> None:
if duplicate_uncles:
raise ValidationError(
"Block contains duplicate uncles:\n"
" - {0}".format(' - '.join(duplicate_uncles))
" - {}".format(' - '.join(duplicate_uncles))
)

recent_ancestors = tuple(
Expand All @@ -657,21 +655,21 @@ def validate_uncles(self, block: BlockAPI) -> None:
# ensure the uncle has not already been included.
if uncle.hash in recent_uncle_hashes:
raise ValidationError(
"Duplicate uncle: {0}".format(encode_hex(uncle.hash))
"Duplicate uncle: {}".format(encode_hex(uncle.hash))
)

# ensure that the uncle is not one of the canonical chain blocks.
if uncle.hash in recent_ancestor_hashes:
raise ValidationError(
"Uncle {0} cannot be an ancestor of {1}".format(
"Uncle {} cannot be an ancestor of {}".format(
encode_hex(uncle.hash), encode_hex(block.hash)))

# ensure that the uncle was built off of one of the canonical chain
# blocks.
if uncle.parent_hash not in recent_ancestor_hashes or (
uncle.parent_hash == block.header.parent_hash):
raise ValidationError(
"Uncle's parent {0} is not an ancestor of {1}".format(
"Uncle's parent {} is not an ancestor of {}".format(
encode_hex(uncle.parent_hash), encode_hex(block.hash)))

# Now perform VM level validation of the uncle
Expand All @@ -681,7 +679,7 @@ def validate_uncles(self, block: BlockAPI) -> None:
uncle_parent = self.get_block_header_by_hash(uncle.parent_hash)
except HeaderNotFound:
raise ValidationError(
"Uncle ancestor not found: {0}".format(uncle.parent_hash)
f"Uncle ancestor not found: {uncle.parent_hash}"
)

uncle_vm_class = self.get_vm_class_for_block_number(uncle.block_number)
Expand Down
12 changes: 6 additions & 6 deletions eth/chains/tester/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from eth.vm.forks.homestead import HomesteadVM


class MaintainGasLimitMixin(object):
class MaintainGasLimitMixin:
@classmethod
def create_header_from_parent(cls,
parent_header: BlockHeaderAPI,
Expand All @@ -43,7 +43,7 @@ def create_header_from_parent(cls,
Call the parent class method maintaining the same gas_limit as the
previous block.
"""
return super(MaintainGasLimitMixin, cls).create_header_from_parent( # type: ignore
return super().create_header_from_parent( # type: ignore
parent_header,
**assoc(header_params, 'gas_limit', parent_header.gas_limit)
)
Expand Down Expand Up @@ -81,17 +81,17 @@ def _generate_vm_configuration(*fork_start_blocks: ForkStartBlocks,

# Validate that there are no fork names which are not represented in the
# mainnet chain.
fork_names = set(
fork_names = {
fork_name for
_, fork_name
in fork_start_blocks
if isinstance(fork_name, str)
)
}
unknown_forks = sorted(fork_names.difference(
MAINNET_VMS.keys()
))
if unknown_forks:
raise ValidationError("Configuration contains unknown forks: {0}".format(unknown_forks))
raise ValidationError(f"Configuration contains unknown forks: {unknown_forks}")

# Validate that *if* an explicit value was passed in for dao_start_block
# that the Homestead fork rules are part of the VM configuration.
Expand All @@ -103,7 +103,7 @@ def _generate_vm_configuration(*fork_start_blocks: ForkStartBlocks,
)

# If no VM is set to start at block 0, default to the frontier VM
start_blocks = set(start_block for start_block, _ in fork_start_blocks)
start_blocks = {start_block for start_block, _ in fork_start_blocks}
if 0 not in start_blocks:
yield GENESIS_BLOCK_NUMBER, MAINNET_VMS['frontier']

Expand Down
10 changes: 5 additions & 5 deletions eth/db/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_block_uncles(self, uncles_hash: Hash32) -> Tuple[BlockHeaderAPI, ...]:
encoded_uncles = self.db[uncles_hash]
except KeyError:
raise HeaderNotFound(
"No uncles found for hash {0}".format(uncles_hash)
f"No uncles found for hash {uncles_hash}"
)
else:
return tuple(rlp.decode(encoded_uncles, sedes=rlp.sedes.CountableList(BlockHeader)))
Expand Down Expand Up @@ -298,15 +298,15 @@ def get_transaction_by_index(
try:
block_header = self.get_canonical_block_header_by_number(block_number)
except HeaderNotFound:
raise TransactionNotFound("Block {} is not in the canonical chain".format(block_number))
raise TransactionNotFound(f"Block {block_number} is not in the canonical chain")
transaction_db = HexaryTrie(self.db, root_hash=block_header.transaction_root)
encoded_index = rlp.encode(transaction_index)
encoded_transaction = transaction_db[encoded_index]
if encoded_transaction != b'':
return rlp.decode(encoded_transaction, sedes=transaction_class)
else:
raise TransactionNotFound(
"No transaction is at index {} of block {}".format(transaction_index, block_number))
f"No transaction is at index {transaction_index} of block {block_number}")

def get_transaction_index(self, transaction_hash: Hash32) -> Tuple[BlockNumber, int]:
"""
Expand Down Expand Up @@ -337,7 +337,7 @@ def get_receipt_by_index(self,
try:
block_header = self.get_canonical_block_header_by_number(block_number)
except HeaderNotFound:
raise ReceiptNotFound("Block {} is not in the canonical chain".format(block_number))
raise ReceiptNotFound(f"Block {block_number} is not in the canonical chain")

receipt_db = HexaryTrie(db=self.db, root_hash=block_header.receipt_root)
receipt_key = rlp.encode(receipt_index)
Expand All @@ -346,7 +346,7 @@ def get_receipt_by_index(self,
return rlp.decode(receipt_data, sedes=Receipt)
else:
raise ReceiptNotFound(
"Receipt with index {} not found in block".format(receipt_index))
f"Receipt with index {receipt_index} not found in block")

@staticmethod
def _get_block_transaction_data(db: DatabaseAPI, transaction_root: Hash32) -> Iterable[Hash32]:
Expand Down
4 changes: 2 additions & 2 deletions eth/db/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ def __repr__(self) -> str:
if val is DELETED
]
updated = [
"key=%s to val=%s" % (encode_hex(key), encode_hex(cast(bytes, val)))
"key={} to val={}".format(encode_hex(key), encode_hex(cast(bytes, val)))
for key, val in self._changes.items()
if val is not DELETED
]
return "<DBDiff: deletions=%r, updates=%r>" % (deleted, updated)
return f"<DBDiff: deletions={deleted!r}, updates={updated!r}>"

def __len__(self) -> int:
return len(self._changes)
Expand Down
Loading