Skip to content

Commit

Permalink
lint: ignore W503 instead of W504 (line break before/after binary ope…
Browse files Browse the repository at this point in the history
…rator).

PEP8 says it's nicer to have line breaks before binary operators:

> Following the tradition from mathematics usually results in
> more readable code:
> ...
  • Loading branch information
veox committed May 29, 2020
1 parent 76309d2 commit cd5bdcb
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 37 deletions.
8 changes: 4 additions & 4 deletions eth/_utils/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def calculate_intrinsic_gas(
else:
create_cost = 0
return (
gas_schedule.gas_tx +
num_zero_bytes * gas_schedule.gas_txdatazero +
num_non_zero_bytes * gas_schedule.gas_txdatanonzero +
create_cost
gas_schedule.gas_tx
+ num_zero_bytes * gas_schedule.gas_txdatazero
+ num_non_zero_bytes * gas_schedule.gas_txdatanonzero
+ create_cost
)
10 changes: 5 additions & 5 deletions eth/consensus/clique/snapshot_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,16 @@ def get_snapshot(self, block_number: int, block_hash: Hash32) -> Snapshot:
# Otherwise, we can retrieve it on the fly
header = self._chain_db.get_block_header_by_hash(block_hash)
except HeaderNotFound:
raise SnapshotNotFound(f"Can not get snapshot for {block_hash!r} at {block_number}")
raise SnapshotNotFound(f"Can not get snapshot for {block_hash} at {block_number}")
else:
if header.block_number != block_number:
raise SnapshotNotFound(
f"Can not get snapshot for {block_hash!r} at {block_number}"
f"Can not get snapshot for {block_hash} at {block_number}"
)
else:
return self._create_snapshot_from_checkpoint_header(header)

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

def add_snapshot(self, mutable_snapshot: MutableSnapshot) -> Snapshot:
"""
Expand All @@ -261,8 +261,8 @@ def get_snapshot_from_db(self, block_hash: Hash32) -> Snapshot:
encoded_key = self._chain_db.db[key]
except KeyError as e:
raise SnapshotNotFound(
f"Can not get on-disk snapshot for {block_hash!r}"
) from e
f"Can not get on-disk snapshot for {block_hash}"
)
else:
return decode_snapshot(encoded_key)

Expand Down
10 changes: 5 additions & 5 deletions eth/precompiles/modexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def _compute_adjusted_exponent_length(exponent_length: int,
else:
first_32_bytes_as_int = big_endian_to_int(first_32_exponent_bytes)
return (
8 * (exponent_length - 32) +
get_highest_bit_index(first_32_bytes_as_int)
8 * (exponent_length - 32)
+ get_highest_bit_index(first_32_bytes_as_int)
)


Expand Down Expand Up @@ -78,9 +78,9 @@ def _compute_modexp_gas_fee(data: bytes) -> int:
complexity = _compute_complexity(max(modulus_length, base_length))

gas_fee = (
complexity *
max(adjusted_exponent_length, 1) //
constants.GAS_MOD_EXP_QUADRATIC_DENOMINATOR
complexity
* max(adjusted_exponent_length, 1)
// constants.GAS_MOD_EXP_QUADRATIC_DENOMINATOR
)
return gas_fee

Expand Down
4 changes: 2 additions & 2 deletions eth/vm/forks/byzantium/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def compute_difficulty(
has_uncles = parent_header.uncles_hash != EMPTY_UNCLE_HASH
adj_factor = max(
(
(2 if has_uncles else 1) -
((timestamp - parent_timestamp) // BYZANTIUM_DIFFICULTY_ADJUSTMENT_CUTOFF)
(2 if has_uncles else 1)
- ((timestamp - parent_timestamp) // BYZANTIUM_DIFFICULTY_ADJUSTMENT_CUTOFF)
),
-99,
)
Expand Down
4 changes: 2 additions & 2 deletions eth/vm/forks/spurious_dragon/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def finalize_computation(self,

for account in touched_accounts:
should_delete = (
self.vm_state.account_exists(account) and
self.vm_state.account_is_empty(account)
self.vm_state.account_exists(account)
and self.vm_state.account_is_empty(account)
)
if should_delete:
self.vm_state.logger.debug2(
Expand Down
4 changes: 2 additions & 2 deletions eth/vm/logic/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ def compute_msg_extra_gas(self,
to: Address,
value: int) -> int:
account_is_dead = (
not computation.state.account_exists(to) or
computation.state.account_is_empty(to)
not computation.state.account_exists(to)
or computation.state.account_is_empty(to)
)

transfer_gas_fee = constants.GAS_CALLVALUE if value else 0
Expand Down
4 changes: 2 additions & 2 deletions eth/vm/logic/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def selfdestruct_eip150(computation: ComputationAPI) -> None:
def selfdestruct_eip161(computation: ComputationAPI) -> None:
beneficiary = force_bytes_to_address(computation.stack_pop1_bytes())
is_dead = (
not computation.state.account_exists(beneficiary) or
computation.state.account_is_empty(beneficiary)
not computation.state.account_exists(beneficiary)
or computation.state.account_is_empty(beneficiary)
)
if is_dead and computation.state.get_balance(computation.msg.storage_address):
computation.consume_gas(
Expand Down
6 changes: 3 additions & 3 deletions eth/vm/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ def persist(self) -> MetaWitnessAPI:
def get_ancestor_hash(self, block_number: int) -> Hash32:
ancestor_depth = self.block_number - block_number - 1
is_ancestor_depth_out_of_range = (
ancestor_depth >= MAX_PREV_HEADER_DEPTH or
ancestor_depth < 0 or
block_number < 0
ancestor_depth >= MAX_PREV_HEADER_DEPTH
or ancestor_depth < 0
or block_number < 0
)
if is_ancestor_depth_out_of_range:
return Hash32(b'')
Expand Down
18 changes: 9 additions & 9 deletions tests/core/vm/test_rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def test_rewards(vm_fn, miner_1_balance, miner_2_balance):

# We first test if the balance matches what we would determine
# if we made all the API calls involved ourselves.
assert coinbase_balance == (vm.get_block_reward() *
TOTAL_BLOCKS_CANONICAL_CHAIN +
vm.get_nephew_reward())
assert coinbase_balance == (vm.get_block_reward()
* TOTAL_BLOCKS_CANONICAL_CHAIN
+ vm.get_nephew_reward())
assert other_miner_balance == vm.get_uncle_reward(block.number, uncle)

# But we also ensure the balance matches the numbers that we calculated on paper
Expand Down Expand Up @@ -181,9 +181,9 @@ def test_rewards_uncle_created_at_different_generations(

# We first test if the balance matches what we would determine
# if we made all the API calls involved ourselves.
assert coinbase_balance == (vm.get_block_reward() *
TOTAL_BLOCKS_CANONICAL_CHAIN +
vm.get_nephew_reward())
assert coinbase_balance == (vm.get_block_reward()
* TOTAL_BLOCKS_CANONICAL_CHAIN
+ vm.get_nephew_reward())

assert other_miner_balance == vm.get_uncle_reward(block.number, uncle)

Expand Down Expand Up @@ -298,9 +298,9 @@ def test_rewards_nephew_uncle_different_vm(
# We first test if the balance matches what we would determine
# if we made all the API calls involved ourselves.
assert coinbase_balance == (
uncle_vm.get_block_reward() * 3 +
nephew_vm.get_block_reward() * (TOTAL_BLOCKS_CANONICAL_CHAIN - 3) +
vm.get_nephew_reward()
uncle_vm.get_block_reward() * 3
+ nephew_vm.get_block_reward() * (TOTAL_BLOCKS_CANONICAL_CHAIN - 3)
+ vm.get_nephew_reward()
)
assert other_miner_balance == vm.get_uncle_reward(block.number, uncle)

Expand Down
8 changes: 5 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ ignore =
# E252 missing whitespace around parameter equals
# Already used too much in the codebase at the point of introduction.
E252,
# W504 line break after binary operator
# It's either this or W503 (line break _before_ binary operator), pick your poison
W504
# W503 line break before binary operator
# It's either this or W504 (line break _after_ binary operator), pick your poison.
# W503 gets enabled when E252 gets ignored, see:
# https://github.com/ethereum/py-evm/pull/1940#discussion_r432606845
W503

[testenv]
usedevelop=True
Expand Down

0 comments on commit cd5bdcb

Please sign in to comment.