Skip to content

Commit 7afe050

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

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)

tests/core/chain-object/test_header_chain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ def test_header_chain_import_block(header_chain, genesis_header):
103103

104104
for header in chain_b:
105105
res, _ = header_chain.import_header(header)
106-
assert res == tuple()
106+
assert res == ()
107107
assert_headers_eq(header_chain.header, chain_a[-1])
108108

109109
for idx, header in enumerate(chain_c, 1):
110110
res, _ = header_chain.import_header(header)
111111
if idx <= 3:
112112
# prior to passing up `chain_a` each import should not return new
113113
# canonical headers.
114-
assert res == tuple()
114+
assert res == ()
115115
assert_headers_eq(header_chain.header, chain_a[-1])
116116
elif idx == 4:
117117
# at the point where `chain_c` passes `chain_a` we should get the

tests/core/consensus/test_clique_encoding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
)
5151

5252

53-
ADDRESS_TALLY_PAIRS = [(key, val) for key, val in SNAPSHOT_1.tallies.items()]
53+
ADDRESS_TALLY_PAIRS = list(SNAPSHOT_1.tallies.items())
5454

5555

5656
@pytest.mark.parametrize(

tests/core/tester/test_generate_vm_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CustomFrontierVM(FrontierVM):
3030
"args,kwargs,expected",
3131
(
3232
(
33-
tuple(),
33+
(),
3434
{},
3535
((0, Forks.Berlin),),
3636
),

tests/core/validation/test_eth1_validation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
@pytest.mark.parametrize(
3838
"value,is_valid",
3939
(
40-
(tuple(), True),
40+
((), True),
4141
([], True),
4242
({}, True),
4343
(set(), True),
@@ -60,7 +60,7 @@ def test_validate_unique(value, is_valid):
6060
@pytest.mark.parametrize(
6161
"value,is_valid",
6262
(
63-
(tuple(), False),
63+
((), False),
6464
([], False),
6565
({}, False),
6666
(set(), False),
@@ -81,7 +81,7 @@ def test_validate_is_bytes(value, is_valid):
8181
@pytest.mark.parametrize(
8282
"value,is_valid",
8383
(
84-
(tuple(), False),
84+
((), False),
8585
([], False),
8686
({}, False),
8787
(set(), False),
@@ -101,7 +101,7 @@ def test_validate_is_integer(value, is_valid):
101101
@pytest.mark.parametrize(
102102
"value,is_valid",
103103
(
104-
(tuple(), False),
104+
((), False),
105105
([], False),
106106
({}, False),
107107
(set(), False),
@@ -122,7 +122,7 @@ def test_validate_is_boolean(value, is_valid):
122122
@pytest.mark.parametrize(
123123
"value,length,is_valid",
124124
(
125-
(tuple(), 0, True),
125+
((), 0, True),
126126
([1], 1, True),
127127
({'A': 'B', 'C': 1}, 3, False),
128128
({'A', 'B', 1, 2}, 4, True),
@@ -142,7 +142,7 @@ def test_validate_length(value, length, is_valid):
142142
@pytest.mark.parametrize(
143143
"value,maximum_length,is_valid",
144144
(
145-
(tuple(), 0, True),
145+
((), 0, True),
146146
([1], 0, False),
147147
({'A': 'B', 'C': 1}, 3, True),
148148
({'A', 'B', 1, 2}, 2, False),
@@ -280,7 +280,7 @@ def test_validate_word(value, is_valid):
280280
@pytest.mark.parametrize(
281281
"value,is_valid",
282282
(
283-
(tuple(), False),
283+
((), False),
284284
('a', False),
285285
(-1, False),
286286
(0, True),
@@ -371,7 +371,7 @@ def test_validate_lt_secpk1n2(value, is_valid):
371371
@pytest.mark.parametrize(
372372
"block_number,is_valid",
373373
(
374-
(tuple(), False),
374+
((), False),
375375
([], False),
376376
({}, False),
377377
(set(), False),

tests/core/vm/test_base_computation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_get_accounts_for_deletion_returns(computation):
184184

185185

186186
def test_add_log_entry_starts_empty(computation):
187-
assert computation.get_log_entries() == tuple()
187+
assert computation.get_log_entries() == ()
188188

189189

190190
def test_add_log_entry_raises_if_address_isnt_canonical(computation):

tests/database/test_db_diff.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_database_api_deleted_key_for_deletion(db):
104104
@pytest.mark.parametrize(
105105
'db, series_of_diffs, expected',
106106
(
107-
({b'0': b'0'}, tuple(), {b'0': b'0'}),
107+
({b'0': b'0'}, (), {b'0': b'0'}),
108108
({b'0': b'0'}, ({}, {}), {b'0': b'0'}),
109109
(
110110
{},
@@ -156,7 +156,7 @@ def test_join_diffs(db, series_of_diffs, expected):
156156
@pytest.mark.parametrize(
157157
'series_of_diffs, expected_updates, expected_deletions',
158158
(
159-
(tuple(), {}, []),
159+
((), {}, []),
160160
(({}, {}), {}, []),
161161
(
162162
(
@@ -205,7 +205,7 @@ def test_db_diff_inspection(series_of_diffs, expected_updates, expected_deletion
205205
if expected_updates:
206206
expected_keys, _ = zip(*expected_updates.items())
207207
else:
208-
expected_keys = tuple()
208+
expected_keys = ()
209209
assert actual_diff.pending_keys() == expected_keys
210210
assert actual_diff.pending_items() == tuple(expected_updates.items())
211211
assert actual_diff.deleted_keys() == tuple(expected_deletions)

tests/database/test_header_db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,14 +818,14 @@ def test_headerdb_persist_header_returns_new_canonical_chain(headerdb, genesis_h
818818

819819
for header in chain_b:
820820
res, _ = headerdb.persist_header(header)
821-
assert res == tuple()
821+
assert res == ()
822822

823823
for idx, header in enumerate(chain_c, 1):
824824
res, _ = headerdb.persist_header(header)
825825
if idx <= 3:
826826
# prior to passing up `chain_a` each import should not return new
827827
# canonical headers.
828-
assert res == tuple()
828+
assert res == ()
829829
elif idx == 4:
830830
# at the point where `chain_c` passes `chain_a` we should get the
831831
# headers from `chain_c` up through current.

0 commit comments

Comments
 (0)