Skip to content

Commit 7afe050

Browse files
authored
chore: refactor code quality issues (#1995)
1 parent 440d63c commit 7afe050

File tree

17 files changed

+51
-44
lines changed

17 files changed

+51
-44
lines changed

.deepsource.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version = 1
2+
3+
test_patterns = ["tests/**"]
4+
5+
exclude_patterns = ["fixtures/**"]
6+
7+
[[analyzers]]
8+
name = "python"
9+
enabled = true
10+
11+
[analyzers.meta]
12+
runtime_version = "3.x.x"

eth/_utils/blake2/coders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ def _get_64_bit_little_endian_words(compact_bytes: bytes) -> Iterable[int]:
5555
f"{len(remaining_bytes)}"
5656
)
5757

58-
while len(remaining_bytes):
58+
while remaining_bytes:
5959
word, remaining_bytes = remaining_bytes[:8], remaining_bytes[8:]
6060
yield to_int(bytes(reversed(word)))

eth/_utils/transactions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@
3737

3838

3939
def is_eip_155_signed_transaction(transaction: BaseTransaction) -> bool:
40-
if transaction.v >= EIP155_CHAIN_ID_OFFSET:
41-
return True
42-
else:
43-
return False
40+
return transaction.v >= EIP155_CHAIN_ID_OFFSET
4441

4542

4643
def extract_chain_id(v: int) -> int:

eth/consensus/clique/encoding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def encode_snapshot(snapshot: Snapshot) -> bytes:
8484
return rlp.encode(
8585
[
8686
snapshot.block_hash,
87-
[signer for signer in snapshot.signers],
87+
list(snapshot.signers),
8888
[encode_vote(vote) for vote in snapshot.votes],
8989
[
9090
encode_address_tally_pair((address, tally))

eth/db/account.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,12 @@ def _get_meta_witness(self) -> MetaWitness:
533533

534534
def _validate_generated_root(self) -> None:
535535
db_diff = self._journaldb.diff()
536-
if len(db_diff):
536+
if db_diff:
537537
raise ValidationError(
538538
f"AccountDB had a dirty db when it needed to be clean: {db_diff!r}"
539539
)
540540
trie_diff = self._journaltrie.diff()
541-
if len(trie_diff):
541+
if trie_diff:
542542
raise ValidationError(
543543
f"AccountDB had a dirty trie when it needed to be clean: {trie_diff!r}"
544544
)

eth/db/header.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def _persist_header_chain(
358358
try:
359359
first_header = first(headers_iterator)
360360
except StopIteration:
361-
return tuple(), tuple()
361+
return (), ()
362362

363363
is_genesis = first_header.parent_hash == genesis_parent_hash
364364
if not is_genesis and not cls._header_exists(db, first_header.parent_hash):
@@ -410,7 +410,7 @@ def _persist_header_chain(
410410
if score > head_score:
411411
return cls._set_as_canonical_chain_head(db, curr_chain_head, genesis_parent_hash)
412412

413-
return tuple(), tuple()
413+
return (), ()
414414

415415
@classmethod
416416
def _handle_gap_change(cls,
@@ -473,10 +473,8 @@ def _canonicalize_header(
473473

474474
# Reject if this would make a checkpoint non-canonical
475475
checkpoints = cls._get_checkpoints(db)
476-
attempted_checkpoint_overrides = set(
477-
old for old in old_canonical_headers
478-
if old.hash in checkpoints
479-
)
476+
attempted_checkpoint_overrides = {old for old in old_canonical_headers
477+
if old.hash in checkpoints}
480478
if len(attempted_checkpoint_overrides):
481479
raise CheckpointsMustBeCanonical(
482480
f"Tried to switch chain away from checkpoint(s) {attempted_checkpoint_overrides!r}"

eth/tools/builder/chain/builders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class FrontierOnlyChain(MiningChain):
147147
if chain_class.vm_configuration is not None:
148148
base_configuration = chain_class.vm_configuration
149149
else:
150-
base_configuration = tuple()
150+
base_configuration = ()
151151

152152
vm_configuration = base_configuration + ((BlockNumber(at_block), vm_class),)
153153
validate_vm_configuration(vm_configuration)

eth/tools/fixtures/generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def generate_fixture_tests(metafunc: Any,
8181
else:
8282
all_fixtures = cached_fixture_data
8383

84-
if not len(all_fixtures):
84+
if not all_fixtures:
8585
raise AssertionError(
8686
f"Suspiciously found zero fixtures: {base_fixture_path}"
8787
)

eth/vm/computation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def register_account_for_deletion(self, beneficiary: Address) -> None:
410410

411411
def get_accounts_for_deletion(self) -> Tuple[Tuple[Address, Address], ...]:
412412
if self.is_error:
413-
return tuple()
413+
return ()
414414
else:
415415
return tuple(dict(itertools.chain(
416416
self.accounts_to_delete.items(),
@@ -555,14 +555,14 @@ def apply_computation(cls,
555555
@property
556556
def precompiles(self) -> Dict[Address, Callable[[ComputationAPI], Any]]:
557557
if self._precompiles is None:
558-
return dict()
558+
return {}
559559
else:
560560
return self._precompiles
561561

562562
@classmethod
563563
def get_precompiles(cls) -> Dict[Address, Callable[[ComputationAPI], Any]]:
564564
if cls._precompiles is None:
565-
return dict()
565+
return {}
566566
else:
567567
return cls._precompiles
568568

tests/core/chain-object/test_chain_get_ancestors.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_chain_get_ancestors_from_genesis_block(chain, limit):
3030
assert header.block_number == 0
3131

3232
ancestors = chain.get_ancestors(limit, header)
33-
assert ancestors == tuple()
33+
assert ancestors == ()
3434

3535

3636
def test_chain_get_ancestors_from_block_1(chain):
@@ -39,7 +39,7 @@ def test_chain_get_ancestors_from_block_1(chain):
3939
header = block_1.header
4040
assert header.block_number == 1
4141

42-
assert chain.get_ancestors(0, header) == tuple()
42+
assert chain.get_ancestors(0, header) == ()
4343
assert chain.get_ancestors(1, header) == (genesis,)
4444
assert chain.get_ancestors(2, header) == (genesis,)
4545
assert chain.get_ancestors(5, header) == (genesis,)
@@ -58,7 +58,7 @@ def test_chain_get_ancestors_from_block_5(chain):
5858
header = block_5.header
5959
assert header.block_number == 5
6060

61-
assert chain.get_ancestors(0, header) == tuple()
61+
assert chain.get_ancestors(0, header) == ()
6262
assert chain.get_ancestors(1, header) == (block_4,)
6363
assert chain.get_ancestors(2, header) == (block_4, block_3)
6464
assert chain.get_ancestors(3, header) == (block_4, block_3, block_2)
@@ -103,14 +103,14 @@ def test_chain_get_ancestors_for_fork_chains(chain, fork_chain):
103103
# import the fork blocks into the main chain (ensuring they don't cause a reorg)
104104
block_import_result = chain.import_block(f_block_4)
105105
new_chain = block_import_result.new_canonical_blocks
106-
assert new_chain == tuple()
106+
assert new_chain == ()
107107

108108
block_import_result = chain.import_block(f_block_5)
109109
new_chain = block_import_result.new_canonical_blocks
110-
assert new_chain == tuple()
110+
assert new_chain == ()
111111

112112
# check with a block that has been imported
113-
assert chain.get_ancestors(0, f_block_5.header) == tuple()
113+
assert chain.get_ancestors(0, f_block_5.header) == ()
114114
assert chain.get_ancestors(1, f_block_5.header) == (f_block_4,)
115115
assert chain.get_ancestors(2, f_block_5.header) == (f_block_4, block_3)
116116
assert chain.get_ancestors(3, f_block_5.header) == (f_block_4, block_3, block_2)
@@ -121,7 +121,7 @@ def test_chain_get_ancestors_for_fork_chains(chain, fork_chain):
121121
assert chain.get_ancestors(20, f_block_5.header) == (f_block_4, block_3, block_2, block_1, genesis) # noqa: E501
122122

123123
# check with a block that has NOT been imported
124-
assert chain.get_ancestors(0, f_block_6.header) == tuple()
124+
assert chain.get_ancestors(0, f_block_6.header) == ()
125125
assert chain.get_ancestors(1, f_block_6.header) == (f_block_5,)
126126
assert chain.get_ancestors(2, f_block_6.header) == (f_block_5, f_block_4)
127127
assert chain.get_ancestors(3, f_block_6.header) == (f_block_5, f_block_4, block_3)

0 commit comments

Comments
 (0)