Skip to content

Commit

Permalink
remove some pylint ignores (#18140)
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky authored Jun 18, 2024
1 parent 570d616 commit 3061cd8
Show file tree
Hide file tree
Showing 52 changed files with 215 additions and 233 deletions.
9 changes: 5 additions & 4 deletions benchmarks/block_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
transaction_block_heights = []
last = 225698
file_path = os.path.realpath(__file__)
for delta in open(Path(file_path).parent / "transaction_height_delta", "rb").read():
new = last + delta
transaction_block_heights.append(new)
last = new
with open(Path(file_path).parent / "transaction_height_delta", "rb") as f:
for delta in f.read():
new = last + delta
transaction_block_heights.append(new)
last = new


@dataclass(frozen=True)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/blockchains.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def enable_profiler(profile: bool, name: str) -> Iterator[None]:
check_call(["gprof2dot", "-f", "pstats", "-o", output_file + ".dot", output_file + ".profile"])
with open(output_file + ".png", "w+") as f:
check_call(["dot", "-T", "png", output_file + ".dot"], stdout=f)
print(" output written to: %s.png" % output_file)
print(f" output written to: {output_file}.png")


async def run_test_chain_benchmark() -> None:
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def enable_profiler(profile: bool, name: str) -> Iterator[None]:
check_call(["gprof2dot", "-f", "pstats", "-o", output_file + ".dot", output_file + ".profile"])
with open(output_file + ".png", "w+") as f:
check_call(["dot", "-T", "png", output_file + ".dot"], stdout=f)
print(" output written to: %s.png" % output_file)
print(f" output written to: {output_file}.png")


def make_hash(height: int) -> bytes32:
Expand Down
24 changes: 13 additions & 11 deletions benchmarks/streamable.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,18 @@ def print_row(
stdev_iterations: Union[str, float],
end: str = "\n",
) -> None:
mode = "{:<10}".format(f"{mode}")
us_per_iteration = "{:<12}".format(f"{us_per_iteration}")
stdev_us_per_iteration = "{:>20}".format(f"{stdev_us_per_iteration}")
avg_iterations = "{:>18}".format(f"{avg_iterations}")
stdev_iterations = "{:>22}".format(f"{stdev_iterations}")
print(f"{mode} | {us_per_iteration} | {stdev_us_per_iteration} | {avg_iterations} | {stdev_iterations}", end=end)
print(
" | ".join(
[
f"{mode:<10}",
f"{us_per_iteration:<12}",
f"{stdev_us_per_iteration:>20}",
f"{avg_iterations:>18}",
f"{stdev_iterations:>22}",
]
),
end=end,
)


@dataclass
Expand Down Expand Up @@ -196,11 +202,7 @@ def pop_data(key: str, *, old: Dict[str, Any], new: Dict[str, Any]) -> Tuple[Any


def print_compare_row(c0: str, c1: Union[str, float], c2: Union[str, float], c3: Union[str, float]) -> None:
c0 = "{:<12}".format(f"{c0}")
c1 = "{:<16}".format(f"{c1}")
c2 = "{:<16}".format(f"{c2}")
c3 = "{:<12}".format(f"{c3}")
print(f"{c0} | {c1} | {c2} | {c3}")
print(f"{c0:<12} | {c1:<16} | {c2:<16} | {c3:<12}")


def compare_results(
Expand Down
3 changes: 1 addition & 2 deletions chia/_tests/blockchain/blockchain_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ async def check_block_store_invariant(bc: Blockchain):
# height can only have a single block with in_main_chain set
assert height not in in_chain
in_chain.add(height)
if height > max_height:
max_height = height
max_height = max(max_height, height)

# make sure every height is represented in the set
assert len(in_chain) == max_height + 1
Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/cmds/wallet/test_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ async def get_transaction(self, transaction_id: bytes32) -> TransactionRecord:
parse_mint_asserts = [
"Type: MINT",
"Amount of CAT to mint: 1000",
"Address: {}".format(encode_puzzle_hash(bytes32(b"x" * 32), "xch")),
f"Address: {encode_puzzle_hash(bytes32(b'x' * 32), 'xch')}",
]
run_cli_command_and_assert(capsys, root_dir, parse_mint_args, parse_mint_asserts)

Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/core/cmds/test_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def test_beta_invalid_directories(
beta_path = root_path / "beta"
if write_test:
(beta_path / ".write_test").mkdir(parents=True) # `.write_test` is used in validate_directory_writable
if command == configure:
if command is configure:
generate_beta_config(root_path, True, root_path_populated_with_config)
result = command(root_path, "--path", str(beta_path))
assert result.exit_code == 1
Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/core/data_layer/test_data_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ async def test_get_owned_stores(
for i in range(0, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)
)
await time_out_assert(15, wallet_node.wallet_state_manager.main_wallet.get_confirmed_balance, funds)
async with init_data_layer(wallet_rpc_port=wallet_rpc_port, bt=bt, db_path=tmp_path) as data_layer:
Expand Down
11 changes: 4 additions & 7 deletions chia/_tests/core/full_node/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def test_wallet_coinbase(self, simulator_and_wallet, self_hostname):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))

funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)
)
# funds += calculate_base_farmer_reward(0)
await asyncio.sleep(2)
Expand Down Expand Up @@ -69,7 +69,7 @@ async def test_tx_propagation(self, three_nodes_two_wallets, self_hostname, seed
await full_node_api_0.farm_new_transaction_block(FarmNewBlockProtocol(ph))

funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)
)
await time_out_assert(20, wallet_0.wallet_state_manager.main_wallet.get_confirmed_balance, funds)

Expand Down Expand Up @@ -111,10 +111,7 @@ async def peak_height(fna: FullNodeAPI):
for i in range(1, 8):
await full_node_api_1.farm_new_transaction_block(FarmNewBlockProtocol(bytes32.random(seeded_random)))
funds = sum(
[
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
for i in range(1, num_blocks + 1)
]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)
)
print(f"Funds: {funds}")
await time_out_assert(
Expand Down Expand Up @@ -153,7 +150,7 @@ async def test_mempool_tx_sync(self, three_nodes_two_wallets, self_hostname, see
await full_node_api_2.full_node.add_block(block)

funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)
)
await time_out_assert(20, wallet_0.wallet_state_manager.main_wallet.get_confirmed_balance, funds)

Expand Down
4 changes: 2 additions & 2 deletions chia/_tests/core/util/test_cached_bls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_cached_bls():
sks = [AugSchemeMPL.key_gen(seed + bytes([i])) for i in range(n_keys)]
pks = [sk.get_g1() for sk in sks]

msgs = [("msg-%d" % (i,)).encode() for i in range(n_keys)]
msgs = [f"msg-{i}".encode() for i in range(n_keys)]
sigs = [AugSchemeMPL.sign(sk, msg) for sk, msg in zip(sks, msgs)]
agg_sig = AugSchemeMPL.aggregate(sigs)

Expand Down Expand Up @@ -48,7 +48,7 @@ def test_cached_bls_repeat_pk():
sks = [AugSchemeMPL.key_gen(seed) for i in range(n_keys)] + [AugSchemeMPL.key_gen(std_hash(seed))]
pks = [sk.get_g1() for sk in sks]

msgs = [("msg-%d" % (i,)).encode() for i in range(n_keys + 1)]
msgs = [(f"msg-{i}").encode() for i in range(n_keys + 1)]
sigs = [AugSchemeMPL.sign(sk, msg) for sk, msg in zip(sks, msgs)]
agg_sig = AugSchemeMPL.aggregate(sigs)

Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/util/key_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def add_secret_exponents(self, secret_exponents: List[int]) -> None:
def sign(self, public_key: G1Element, message: bytes) -> G2Element:
secret_exponent = self.dict.get(public_key)
if not secret_exponent:
raise ValueError("unknown pubkey %s" % bytes(public_key).hex())
raise ValueError(f"unknown pubkey {bytes(public_key).hex()}")
bls_private_key = PrivateKey.from_bytes(secret_exponent.to_bytes(32, "big"))
return AugSchemeMPL.sign(bls_private_key, message)

Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/wallet/cat_wallet/test_cat_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async def test_cat_mod(cost_logger: CostLogger, consensus_mode: ConsensusMode) -
record.coin
for record in (await sim_client.get_coin_records_by_puzzle_hash(cat_ph, include_spent_coins=False))
]
total_amount = uint64(sum([c.amount for c in coins]))
total_amount = uint64(sum(c.amount for c in coins))
await do_spend(
sim,
sim_client,
Expand Down
65 changes: 33 additions & 32 deletions chia/_tests/wallet/cat_wallet/test_cat_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def test_cat_creation(self_hostname: str, two_wallet_nodes: OldSimulatorsA
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))

funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)
)

await time_out_assert(20, wallet.get_confirmed_balance, funds)
Expand Down Expand Up @@ -132,7 +132,7 @@ async def test_cat_creation_unique_lineage_store(self_hostname: str, two_wallet_
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))

funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)
)

await time_out_assert(20, wallet.get_confirmed_balance, funds)
Expand Down Expand Up @@ -429,7 +429,7 @@ async def test_cat_reuse_address(self_hostname: str, two_wallet_nodes: OldSimula
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))

funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)
)

await time_out_assert(20, wallet.get_confirmed_balance, funds)
Expand Down Expand Up @@ -526,7 +526,7 @@ async def test_get_wallet_for_asset_id(
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))

funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)
)

await time_out_assert(20, wallet.get_confirmed_balance, funds)
Expand Down Expand Up @@ -580,7 +580,7 @@ async def test_cat_doesnt_see_eve(self_hostname: str, two_wallet_nodes: OldSimul
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))

funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)
)

await time_out_assert(20, wallet.get_confirmed_balance, funds)
Expand Down Expand Up @@ -670,7 +670,7 @@ async def test_cat_spend_multiple(
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))

funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)
)

await time_out_assert(20, wallet_0.get_confirmed_balance, funds)
Expand Down Expand Up @@ -785,7 +785,7 @@ async def test_cat_max_amount_send(
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))

funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)
)

await time_out_assert(20, wallet.get_confirmed_balance, funds)
Expand Down Expand Up @@ -882,7 +882,7 @@ async def test_cat_hint(
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))

funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)]
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks + 1)
)

await time_out_assert(20, wallet.get_confirmed_balance, funds)
Expand Down Expand Up @@ -1093,30 +1093,31 @@ async def test_cat_change_detection(

@pytest.mark.anyio
async def test_unacknowledged_cat_table() -> None:
db_name = Path(tempfile.TemporaryDirectory().name).joinpath("test.sqlite")
db_name.parent.mkdir(parents=True, exist_ok=True)
async with DBWrapper2.managed(database=db_name) as db_wrapper:
interested_store = await WalletInterestedStore.create(db_wrapper)

def asset_id(i: int) -> bytes32:
return bytes32([i] * 32)

def coin_state(i: int) -> CoinState:
return CoinState(Coin(bytes32([0] * 32), bytes32([0] * 32), uint64(i)), None, None)

await interested_store.add_unacknowledged_coin_state(asset_id(0), coin_state(0), None)
await interested_store.add_unacknowledged_coin_state(asset_id(1), coin_state(1), 100)
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(0)) == [(coin_state(0), 0)]
await interested_store.add_unacknowledged_coin_state(asset_id(0), coin_state(0), None)
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(0)) == [(coin_state(0), 0)]
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(1)) == [(coin_state(1), 100)]
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(2)) == []
await interested_store.rollback_to_block(50)
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(1)) == []
await interested_store.delete_unacknowledged_states_for_asset_id(asset_id(1))
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(0)) == [(coin_state(0), 0)]
await interested_store.delete_unacknowledged_states_for_asset_id(asset_id(0))
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(0)) == []
with tempfile.TemporaryDirectory() as temporary_directory:
db_name = Path(temporary_directory).joinpath("test.sqlite")
db_name.parent.mkdir(parents=True, exist_ok=True)
async with DBWrapper2.managed(database=db_name) as db_wrapper:
interested_store = await WalletInterestedStore.create(db_wrapper)

def asset_id(i: int) -> bytes32:
return bytes32([i] * 32)

def coin_state(i: int) -> CoinState:
return CoinState(Coin(bytes32([0] * 32), bytes32([0] * 32), uint64(i)), None, None)

await interested_store.add_unacknowledged_coin_state(asset_id(0), coin_state(0), None)
await interested_store.add_unacknowledged_coin_state(asset_id(1), coin_state(1), 100)
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(0)) == [(coin_state(0), 0)]
await interested_store.add_unacknowledged_coin_state(asset_id(0), coin_state(0), None)
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(0)) == [(coin_state(0), 0)]
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(1)) == [(coin_state(1), 100)]
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(2)) == []
await interested_store.rollback_to_block(50)
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(1)) == []
await interested_store.delete_unacknowledged_states_for_asset_id(asset_id(1))
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(0)) == [(coin_state(0), 0)]
await interested_store.delete_unacknowledged_states_for_asset_id(asset_id(0))
assert await interested_store.get_unacknowledged_states_for_asset_id(asset_id(0)) == []


@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions chia/_tests/wallet/cat_wallet/test_offer_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def generate_secure_bundle(
tail_str: Optional[str] = None,
) -> SpendBundle:
announcement_assertions: List[Program] = [a.to_program() for a in announcements]
selected_coin_amount = sum([c.amount for c in selected_coins])
selected_coin_amount = sum(c.amount for c in selected_coins)
non_primaries = [] if len(selected_coins) < 2 else selected_coins[1:]
inner_solution: List[Any] = [
[51, Offer.ph(), offered_amount], # Offered coin
Expand Down Expand Up @@ -196,7 +196,7 @@ async def test_complex_offer(cost_logger: CostLogger) -> None:
red_notarized_payments = Offer.notarize_payments(red_requested_payments, red_coins_1)
red_announcements = Offer.calculate_announcements(red_notarized_payments, driver_dict)
red_secured_bundle = generate_secure_bundle(
red_coins_1, red_announcements, uint64(sum([c.amount for c in red_coins_1])), tail_str="red"
red_coins_1, red_announcements, uint64(sum(c.amount for c in red_coins_1)), tail_str="red"
)
red_offer = Offer(red_notarized_payments, red_secured_bundle, driver_dict)
assert not red_offer.is_valid()
Expand All @@ -207,7 +207,7 @@ async def test_complex_offer(cost_logger: CostLogger) -> None:
red_notarized_payments_2 = Offer.notarize_payments(red_requested_payments_2, red_coins_2)
red_announcements_2 = Offer.calculate_announcements(red_notarized_payments_2, driver_dict)
red_secured_bundle_2 = generate_secure_bundle(
red_coins_2, red_announcements_2, uint64(sum([c.amount for c in red_coins_2])), tail_str="red"
red_coins_2, red_announcements_2, uint64(sum(c.amount for c in red_coins_2)), tail_str="red"
)
red_offer_2 = Offer(red_notarized_payments_2, red_secured_bundle_2, driver_dict)
assert not red_offer_2.is_valid()
Expand Down
Loading

0 comments on commit 3061cd8

Please sign in to comment.