From 17c461ee9d481ad0a2d59c9142422ae73edc10bf Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 7 Nov 2024 10:24:03 -0800 Subject: [PATCH] Tighten up ruff ignore list --- activated.py | 2 +- benchmarks/streamable.py | 4 +- chia/_tests/core/data_layer/test_data_rpc.py | 2 +- .../_tests/core/data_layer/test_data_store.py | 2 +- chia/_tests/core/data_layer/util.py | 2 +- chia/_tests/core/full_node/test_full_node.py | 2 +- chia/_tests/core/test_farmer_harvester_rpc.py | 2 +- chia/_tests/core/test_full_node_rpc.py | 2 +- chia/_tests/core/test_seeder.py | 2 +- chia/_tests/core/util/test_block_cache.py | 8 +-- chia/_tests/plot_sync/test_receiver.py | 4 +- chia/_tests/wallet/test_conditions.py | 2 +- chia/cmds/configure.py | 4 +- chia/cmds/init_funcs.py | 6 +- chia/cmds/installers.py | 2 + chia/consensus/constants.py | 5 +- chia/daemon/server.py | 2 +- chia/data_layer/s3_plugin_service.py | 2 +- chia/full_node/full_node.py | 2 +- chia/full_node/weight_proof.py | 2 +- chia/plotters/bladebit.py | 2 +- chia/pools/pool_wallet.py | 5 +- chia/rpc/full_node_rpc_api.py | 2 +- chia/rpc/rpc_server.py | 2 +- chia/rpc/util.py | 4 +- chia/rpc/wallet_rpc_api.py | 8 +-- chia/seeder/dns_server.py | 2 +- chia/server/server.py | 7 +- chia/timelord/timelord_state.py | 6 +- chia/util/streamable.py | 2 +- chia/wallet/trade_manager.py | 3 +- chia/wallet/trading/offer.py | 6 +- chia/wallet/transaction_record.py | 2 +- chia/wallet/wallet_state_manager.py | 7 +- installhelper.py | 2 +- ruff.toml | 64 ++++++++----------- tools/chialispp.py | 2 +- 37 files changed, 86 insertions(+), 99 deletions(-) diff --git a/activated.py b/activated.py index f065cc6d46df..1a033c8495a7 100755 --- a/activated.py +++ b/activated.py @@ -33,7 +33,7 @@ def main(*args: str) -> int: script = "activated.sh" command = ["sh", os.fspath(here.joinpath(script)), env.value, *args] - completed_process = subprocess.run(command) + completed_process = subprocess.run(command, check=False) return completed_process.returncode diff --git a/benchmarks/streamable.py b/benchmarks/streamable.py index 366310c2d4d9..8ff2b22291ad 100644 --- a/benchmarks/streamable.py +++ b/benchmarks/streamable.py @@ -236,7 +236,7 @@ def run(data: Data, mode: Mode, runs: int, ms: int, live: bool, output: TextIO, results: dict[Data, dict[Mode, list[list[int]]]] = {} bench_results: dict[str, Any] = {"version": _version, "commit_hash": get_commit_hash()} for current_data, parameter in benchmark_parameter.items(): - if data == Data.all or current_data == data: + if data in (Data.all, current_data): results[current_data] = {} bench_results[current_data] = {} print( @@ -252,7 +252,7 @@ def run(data: Data, mode: Mode, runs: int, ms: int, live: bool, output: TextIO, ) for current_mode, current_mode_parameter in parameter.mode_parameter.items(): results[current_data][current_mode] = [] - if mode == Mode.all or current_mode == mode: + if mode in (Mode.all, current_mode): us_iteration_results: list[int] all_results: list[list[int]] = results[current_data][current_mode] obj = parameter.object_creation_cb() diff --git a/chia/_tests/core/data_layer/test_data_rpc.py b/chia/_tests/core/data_layer/test_data_rpc.py index 2b08621692b9..251e8d3fde88 100644 --- a/chia/_tests/core/data_layer/test_data_rpc.py +++ b/chia/_tests/core/data_layer/test_data_rpc.py @@ -3087,7 +3087,7 @@ async def test_pagination_cmds( ) elif layer == InterfaceLayer.cli: for command in ("get_keys", "get_keys_values", "get_kv_diff"): - if command == "get_keys" or command == "get_keys_values": + if command in ("get_keys", "get_keys_values"): args: list[str] = [ sys.executable, "-m", diff --git a/chia/_tests/core/data_layer/test_data_store.py b/chia/_tests/core/data_layer/test_data_store.py index 79565c5684c1..faa7cd041258 100644 --- a/chia/_tests/core/data_layer/test_data_store.py +++ b/chia/_tests/core/data_layer/test_data_store.py @@ -402,7 +402,7 @@ async def test_batch_update( [0.4, 0.2, 0.2, 0.2], k=1, ) - if op_type == "insert" or op_type == "upsert-insert" or len(keys_values) == 0: + if op_type in ("insert", "upsert-insert") or len(keys_values) == 0: if len(keys_values) == 0: op_type = "insert" key = operation.to_bytes(4, byteorder="big") diff --git a/chia/_tests/core/data_layer/util.py b/chia/_tests/core/data_layer/util.py index 406309f65a24..b97426dd3633 100644 --- a/chia/_tests/core/data_layer/util.py +++ b/chia/_tests/core/data_layer/util.py @@ -157,7 +157,7 @@ def run( kwargs["stderr"] = stderr try: - return subprocess.run(*final_args, **kwargs) + return subprocess.run(*final_args, **kwargs, check=False) except OSError as e: raise Exception(f"failed to run:\n {final_args}\n {kwargs}") from e diff --git a/chia/_tests/core/full_node/test_full_node.py b/chia/_tests/core/full_node/test_full_node.py index abec2bd49baf..1b7b07810cde 100644 --- a/chia/_tests/core/full_node/test_full_node.py +++ b/chia/_tests/core/full_node/test_full_node.py @@ -507,7 +507,7 @@ async def have_msgs(): if msg is not None and not (len(msg.peer_list) == 1): return False peer = msg.peer_list[0] - return (peer.host == self_hostname or peer.host == "127.0.0.1") and peer.port == 1000 + return (peer.host in (self_hostname, "127.0.0.1")) and peer.port == 1000 await time_out_assert_custom_interval(10, 1, have_msgs, True) full_node_1.full_node.full_node_peers.address_manager = AddressManager() diff --git a/chia/_tests/core/test_farmer_harvester_rpc.py b/chia/_tests/core/test_farmer_harvester_rpc.py index 44481966bc58..40fc2e6c6bb5 100644 --- a/chia/_tests/core/test_farmer_harvester_rpc.py +++ b/chia/_tests/core/test_farmer_harvester_rpc.py @@ -47,7 +47,7 @@ async def wait_for_plot_sync(receiver: Receiver, previous_last_sync_id: uint64) -> None: def wait() -> bool: current_last_sync_id = receiver.last_sync().sync_id - return current_last_sync_id != 0 and current_last_sync_id != previous_last_sync_id + return current_last_sync_id not in (0, previous_last_sync_id) await time_out_assert(30, wait) diff --git a/chia/_tests/core/test_full_node_rpc.py b/chia/_tests/core/test_full_node_rpc.py index b20463a76450..179d515ce13d 100644 --- a/chia/_tests/core/test_full_node_rpc.py +++ b/chia/_tests/core/test_full_node_rpc.py @@ -228,7 +228,7 @@ async def test1(two_nodes_sim_and_wallets_services, self_hostname, consensus_mod block_spends = await client.get_block_spends(block.header_hash) assert len(block_spends) == 3 - assert sorted(block_spends, key=lambda x: str(x)) == sorted(coin_spends, key=lambda x: str(x)) + assert sorted(block_spends, key=str) == sorted(coin_spends, key=str) block_spends_with_conditions = await client.get_block_spends_with_conditions(block.header_hash) diff --git a/chia/_tests/core/test_seeder.py b/chia/_tests/core/test_seeder.py index 26cc5c692a07..fd3ed5ffb2ee 100644 --- a/chia/_tests/core/test_seeder.py +++ b/chia/_tests/core/test_seeder.py @@ -164,7 +164,7 @@ async def test_error_conditions( no_peers_response = await make_dns_query(use_tcp, target_address, port, no_peers) assert no_peers_response.rcode() == dns.rcode.NOERROR - if request_type == dns.rdatatype.A or request_type == dns.rdatatype.AAAA: + if request_type in (dns.rdatatype.A, dns.rdatatype.AAAA): assert len(no_peers_response.answer) == 0 # no response, as expected elif request_type == dns.rdatatype.ANY: # ns + soa assert len(no_peers_response.answer) == 2 diff --git a/chia/_tests/core/util/test_block_cache.py b/chia/_tests/core/util/test_block_cache.py index e7ed476aacc5..69c83e1221dc 100644 --- a/chia/_tests/core/util/test_block_cache.py +++ b/chia/_tests/core/util/test_block_cache.py @@ -36,9 +36,9 @@ async def test_block_cache(seeded_random: random.Random) -> None: if i == 0: continue assert await a.prev_block_hash([hh]) == [hashes[i - 1]] - assert a.try_block_record(hh) == BR(i + 1, hashes[i], hashes[i - 1]) - assert a.block_record(hh) == BR(i + 1, hashes[i], hashes[i - 1]) - assert a.height_to_hash(uint32(i + 1)) == hashes[i] - assert a.height_to_block_record(uint32(i + 1)) == BR(i + 1, hashes[i], hashes[i - 1]) + assert a.try_block_record(hh) == BR(i + 1, hh, hashes[i - 1]) + assert a.block_record(hh) == BR(i + 1, hh, hashes[i - 1]) + assert a.height_to_hash(uint32(i + 1)) == hh + assert a.height_to_block_record(uint32(i + 1)) == BR(i + 1, hh, hashes[i - 1]) assert a.contains_block(hh) assert a.contains_height(uint32(i + 1)) diff --git a/chia/_tests/plot_sync/test_receiver.py b/chia/_tests/plot_sync/test_receiver.py index b45b95aa5a9e..fc4e8d062a49 100644 --- a/chia/_tests/plot_sync/test_receiver.py +++ b/chia/_tests/plot_sync/test_receiver.py @@ -132,7 +132,7 @@ async def run_sync_step(receiver: Receiver, sync_step: SyncStepData) -> None: assert receiver.current_sync().state == sync_step.state last_sync_time_before = receiver._last_sync.time_done # For the list types invoke the trigger function in batches - if sync_step.payload_type == PlotSyncPlotList or sync_step.payload_type == PlotSyncPathList: + if sync_step.payload_type in (PlotSyncPlotList, PlotSyncPathList): step_data, _ = sync_step.args assert len(step_data) == 10 # Invoke batches of: 1, 2, 3, 4 items and validate the data against plot store before and after @@ -289,7 +289,7 @@ async def test_to_dict(counts_only: bool, seeded_random: random.Random) -> None: for state in State: await run_sync_step(receiver, sync_steps[state]) - if state != State.idle and state != State.removed and state != State.done: + if state not in (State.idle, State.removed, State.done): expected_plot_files_processed += len(sync_steps[state].args[0]) sync_data = receiver.to_dict()["syncing"] diff --git a/chia/_tests/wallet/test_conditions.py b/chia/_tests/wallet/test_conditions.py index fbdca992d972..cc4155c8dfab 100644 --- a/chia/_tests/wallet/test_conditions.py +++ b/chia/_tests/wallet/test_conditions.py @@ -381,7 +381,7 @@ def test_invalid_condition( ], prg: bytes, ) -> None: - if (cond == Remark or cond == UnknownCondition) and prg != b"\x80": + if (cond in (Remark, UnknownCondition)) and prg != b"\x80": pytest.skip("condition takes arbitrary arguments") with pytest.raises((ValueError, EvalError, KeyError)): diff --git a/chia/cmds/configure.py b/chia/cmds/configure.py index 8ebac359a06c..a8d662edf1f7 100644 --- a/chia/cmds/configure.py +++ b/chia/cmds/configure.py @@ -103,7 +103,7 @@ def configure( print("Target peer count updated") change_made = True if testnet: - if testnet == "true" or testnet == "t": + if testnet in ("true", "t"): print("Setting Testnet") # check if network_overrides.constants.testnet11 exists if ( @@ -167,7 +167,7 @@ def configure( print("Default full node port, introducer and network setting updated") change_made = True - elif testnet == "false" or testnet == "f": + elif testnet in ("false", "f"): print("Setting Mainnet") mainnet_port = "8444" mainnet_introducer = "introducer.chia.net" diff --git a/chia/cmds/init_funcs.py b/chia/cmds/init_funcs.py index e6a4794e4fca..1b5e3db78aa2 100644 --- a/chia/cmds/init_funcs.py +++ b/chia/cmds/init_funcs.py @@ -41,8 +41,8 @@ def dict_add_new_default(updated: dict[str, Any], default: dict[str, Any], do_not_migrate_keys: dict[str, Any]) -> None: - for k in do_not_migrate_keys: - if k in updated and do_not_migrate_keys[k] == "": + for k, v in do_not_migrate_keys.items(): + if k in updated and v == "": updated.pop(k) for k, v in default.items(): ignore = False @@ -56,7 +56,7 @@ def dict_add_new_default(updated: dict[str, Any], default: dict[str, Any], do_no # If there is an intermediate key with empty string value, do not migrate all descendants if do_not_migrate_keys.get(k, None) == "": do_not_migrate_keys[k] = v - dict_add_new_default(updated[k], default[k], do_not_migrate_keys.get(k, {})) + dict_add_new_default(updated[k], v, do_not_migrate_keys.get(k, {})) elif k not in updated or ignore is True: updated[k] = v diff --git a/chia/cmds/installers.py b/chia/cmds/installers.py index fd0cae1f553f..653dab07183e 100644 --- a/chia/cmds/installers.py +++ b/chia/cmds/installers.py @@ -61,6 +61,7 @@ def test_command(expected_chia_version_str: str, require_madmax: bool) -> None: capture_output=True, encoding="utf-8", timeout=adjusted_timeout(30), + check=False, ) assert chia_version_process.returncode == 0 assert chia_version_process.stderr == "" @@ -76,6 +77,7 @@ def test_command(expected_chia_version_str: str, require_madmax: bool) -> None: capture_output=True, encoding="utf-8", timeout=adjusted_timeout(30), + check=False, ) print() diff --git a/chia/consensus/constants.py b/chia/consensus/constants.py index 3e77f0880a21..c07f1818672b 100644 --- a/chia/consensus/constants.py +++ b/chia/consensus/constants.py @@ -3,7 +3,7 @@ import logging from typing import Any -from chia_rs import ConsensusConstants as ConsensusConstants +from chia_rs import ConsensusConstants from chia.util.byte_types import hexstr_to_bytes from chia.util.hash import std_hash @@ -47,3 +47,6 @@ def replace_str_to_bytes(constants: ConsensusConstants, **changes: Any) -> Conse # TODO: this is too magical here and is really only used for configuration unmarshalling return constants.replace(**filtered_changes) # type: ignore[arg-type] + + +__all__ = ["ConsensusConstants", "replace_str_to_bytes"] diff --git a/chia/daemon/server.py b/chia/daemon/server.py index c59fd47480ec..8d71d9e72ec9 100644 --- a/chia/daemon/server.py +++ b/chia/daemon/server.py @@ -1020,7 +1020,7 @@ def _build_plotting_command_args(self, request: Any, ignoreCount: bool, index: i # plotter command must be either # 'chia plotters bladebit ramplot' or 'chia plotters bladebit diskplot' plot_type = request["plot_type"] - assert plot_type == "diskplot" or plot_type == "ramplot" or plot_type == "cudaplot" + assert plot_type in ("diskplot", "ramplot", "cudaplot") command_args.append(plot_type) command_args.extend(self._common_plotting_command_args(request, ignoreCount)) diff --git a/chia/data_layer/s3_plugin_service.py b/chia/data_layer/s3_plugin_service.py index a9489e8f1fa2..3422d87fc8b0 100644 --- a/chia/data_layer/s3_plugin_service.py +++ b/chia/data_layer/s3_plugin_service.py @@ -14,7 +14,7 @@ from typing import Any, Optional, overload from urllib.parse import urlparse -import boto3 as boto3 +import boto3 import yaml from aiohttp import web from botocore.exceptions import ClientError diff --git a/chia/full_node/full_node.py b/chia/full_node/full_node.py index 7f3a83001228..f7e1ee20ce5c 100644 --- a/chia/full_node/full_node.py +++ b/chia/full_node/full_node.py @@ -1609,7 +1609,7 @@ async def add_prevalidated_blocks( agg_state_change_summary.additions + state_change_summary.additions, agg_state_change_summary.new_rewards + state_change_summary.new_rewards, ) - elif result == AddBlockResult.INVALID_BLOCK or result == AddBlockResult.DISCONNECTED_BLOCK: + elif result in (AddBlockResult.INVALID_BLOCK, AddBlockResult.DISCONNECTED_BLOCK): if error is not None: self.log.error(f"Error: {error}, Invalid block from peer: {peer_info} ") return agg_state_change_summary, error diff --git a/chia/full_node/weight_proof.py b/chia/full_node/weight_proof.py index 4c8f195f310f..ff0a1d7fad83 100644 --- a/chia/full_node/weight_proof.py +++ b/chia/full_node/weight_proof.py @@ -880,7 +880,7 @@ def _map_sub_epoch_summaries( if idx < len(sub_epoch_data) - 1: delta = 0 if idx > 0: - delta = sub_epoch_data[idx].num_blocks_overflow + delta = data.num_blocks_overflow log.debug(f"sub epoch {idx} start weight is {total_weight + curr_difficulty} ") sub_epoch_weight_list.append(uint128(total_weight + curr_difficulty)) total_weight = uint128( diff --git a/chia/plotters/bladebit.py b/chia/plotters/bladebit.py index dfce9a3b9b32..47ec6487318e 100644 --- a/chia/plotters/bladebit.py +++ b/chia/plotters/bladebit.py @@ -286,7 +286,7 @@ def plot_bladebit(args, chia_root_path, root_path): args.connect_to_daemon, ) ) - if args.plot_type == "ramplot" or args.plot_type == "diskplot" or args.plot_type == "cudaplot": + if args.plot_type in ("ramplot", "diskplot", "cudaplot"): plot_type = args.plot_type else: plot_type = "diskplot" diff --git a/chia/pools/pool_wallet.py b/chia/pools/pool_wallet.py index 7b1c1025f50c..9013a51ca924 100644 --- a/chia/pools/pool_wallet.py +++ b/chia/pools/pool_wallet.py @@ -177,10 +177,7 @@ def _verify_pool_state(cls, state: PoolState) -> Optional[str]: if state.state == PoolSingletonState.SELF_POOLING.value: return cls._verify_self_pooled(state) - elif ( - state.state == PoolSingletonState.FARMING_TO_POOL.value - or state.state == PoolSingletonState.LEAVING_POOL.value - ): + elif state.state in (PoolSingletonState.FARMING_TO_POOL.value, PoolSingletonState.LEAVING_POOL.value): return cls._verify_pooling_state(state) else: return "Internal Error" diff --git a/chia/rpc/full_node_rpc_api.py b/chia/rpc/full_node_rpc_api.py index 10087338357e..73cbc802739a 100644 --- a/chia/rpc/full_node_rpc_api.py +++ b/chia/rpc/full_node_rpc_api.py @@ -132,7 +132,7 @@ async def _state_changed(self, change: str, change_data: Optional[dict[str, Any] change_data = {} payloads = [] - if change == "new_peak" or change == "sync_mode": + if change in ("new_peak", "sync_mode"): data = await self.get_blockchain_state({}) assert data is not None payloads.append( diff --git a/chia/rpc/rpc_server.py b/chia/rpc/rpc_server.py index 38b9c7c18236..fb316a4783ea 100644 --- a/chia/rpc/rpc_server.py +++ b/chia/rpc/rpc_server.py @@ -202,7 +202,7 @@ async def _state_changed(self, change: str, change_data: Optional[dict[str, Any] return None payloads: list[WsRpcMessage] = await self.rpc_api._state_changed(change, change_data) - if change == "add_connection" or change == "close_connection" or change == "peer_changed_peak": + if change in ("add_connection", "close_connection", "peer_changed_peak"): data = await self.get_connections({}) if data is not None: payload = create_payload_dict( diff --git a/chia/rpc/util.py b/chia/rpc/util.py index af31786fe09a..9c57ae4c153d 100644 --- a/chia/rpc/util.py +++ b/chia/rpc/util.py @@ -209,9 +209,7 @@ async def rpc_endpoint( if ( func.__name__ == "create_new_wallet" and request["wallet_type"] == "pool_wallet" - or func.__name__ == "pw_join_pool" - or func.__name__ == "pw_self_pool" - or func.__name__ == "pw_absorb_rewards" + or func.__name__ in ("pw_join_pool", "pw_self_pool", "pw_absorb_rewards") ): # Theses RPCs return not "convenience" for some reason response["transaction"] = new_txs[-1].to_json_dict() diff --git a/chia/rpc/wallet_rpc_api.py b/chia/rpc/wallet_rpc_api.py index 9da56239cec0..9348adab20e5 100644 --- a/chia/rpc/wallet_rpc_api.py +++ b/chia/rpc/wallet_rpc_api.py @@ -1785,7 +1785,7 @@ async def verify_signature(self, request: dict[str, Any]) -> EndpointResult: except ValueError: raise ValueError(f"Invalid signing mode: {signing_mode_str!r}") - if signing_mode == SigningMode.CHIP_0002 or signing_mode == SigningMode.CHIP_0002_P2_DELEGATED_CONDITIONS: + if signing_mode in (SigningMode.CHIP_0002, SigningMode.CHIP_0002_P2_DELEGATED_CONDITIONS): # CHIP-0002 message signatures are made over the tree hash of: # ("Chia Signed Message", message) message_to_verify: bytes = Program.to((CHIP_0002_SIGN_MESSAGE_PREFIX, input_message)).get_tree_hash() @@ -2086,11 +2086,11 @@ async def create_offer_for_ids( driver_dict[bytes32.from_hexstr(key)] = PuzzleInfo(value) modified_offer: dict[Union[int, bytes32], int] = {} - for key in offer: + for key, val in offer.items(): try: - modified_offer[bytes32.from_hexstr(key)] = offer[key] + modified_offer[bytes32.from_hexstr(key)] = val except ValueError: - modified_offer[int(key)] = offer[key] + modified_offer[int(key)] = val async with self.service.wallet_state_manager.lock: result = await self.service.wallet_state_manager.trade_manager.create_offer_for_ids( diff --git a/chia/seeder/dns_server.py b/chia/seeder/dns_server.py index d0efe7de6ad7..9c9ac3708b5f 100644 --- a/chia/seeder/dns_server.py +++ b/chia/seeder/dns_server.py @@ -504,7 +504,7 @@ async def dns_response(self, request: DNSRecord) -> DNSRecord: valid_domain = True for response in domain_responses: rqt: int = getattr(QTYPE, response.__class__.__name__) - if question_type == rqt or question_type == QTYPE.ANY: + if question_type in (rqt, QTYPE.ANY): reply.add_answer(RR(rname=qname, rtype=rqt, rclass=1, ttl=ttl, rdata=response)) if not valid_domain and len(reply.rr) == 0: # if we didn't find any records to return reply.header.rcode = RCODE.NXDOMAIN diff --git a/chia/server/server.py b/chia/server/server.py index 71f75279998b..6c98cafcf584 100644 --- a/chia/server/server.py +++ b/chia/server/server.py @@ -254,7 +254,7 @@ async def garbage_collect_connections_task(self) -> None: if connection.closed: to_remove.append(connection) elif ( - self._local_type == NodeType.FULL_NODE or self._local_type == NodeType.WALLET + self._local_type in (NodeType.FULL_NODE, NodeType.WALLET) ) and connection.connection_type == NodeType.FULL_NODE: if is_crawler is not None: if time.time() - connection.creation_time > 5: @@ -541,8 +541,9 @@ async def connection_closed( ban_until: float = time.time() + ban_time self.log.warning(f"Banning {connection.peer_info.host} for {ban_time} seconds") if connection.peer_info.host in self.banned_peers: - if ban_until > self.banned_peers[connection.peer_info.host]: - self.banned_peers[connection.peer_info.host] = ban_until + self.banned_peers[connection.peer_info.host] = max( + ban_until, self.banned_peers[connection.peer_info.host] + ) else: self.banned_peers[connection.peer_info.host] = ban_until diff --git a/chia/timelord/timelord_state.py b/chia/timelord/timelord_state.py index e6e35c11cc07..a162f4977b46 100644 --- a/chia/timelord/timelord_state.py +++ b/chia/timelord/timelord_state.py @@ -121,7 +121,7 @@ def can_infuse_block(self, overflow: bool) -> bool: if overflow and self.new_epoch: # No overflows in new epoch return False - if self.state_type == StateType.FIRST_SUB_SLOT or self.state_type == StateType.END_OF_SUB_SLOT: + if self.state_type in (StateType.FIRST_SUB_SLOT, StateType.END_OF_SUB_SLOT): return True ss_start_iters = self.get_total_iters() - self.get_last_ip() already_infused_count: int = 0 @@ -160,7 +160,7 @@ def just_infused_sub_epoch_summary(self) -> bool: return self.state_type == StateType.END_OF_SUB_SLOT and self.infused_ses def get_next_sub_epoch_summary(self) -> Optional[SubEpochSummary]: - if self.state_type == StateType.FIRST_SUB_SLOT or self.state_type == StateType.END_OF_SUB_SLOT: + if self.state_type in (StateType.FIRST_SUB_SLOT, StateType.END_OF_SUB_SLOT): # Can only infuse SES after a peak (in an end of sub slot) return None assert self.peak is not None @@ -233,7 +233,7 @@ def get_initial_form(self, chain: Chain) -> Optional[ClassgroupElement]: else: return None elif self.state_type == StateType.END_OF_SUB_SLOT: - if chain == Chain.CHALLENGE_CHAIN or chain == Chain.REWARD_CHAIN: + if chain in (Chain.CHALLENGE_CHAIN, Chain.REWARD_CHAIN): return ClassgroupElement.get_default_element() if chain == Chain.INFUSED_CHALLENGE_CHAIN: assert self.subslot_end is not None diff --git a/chia/util/streamable.py b/chia/util/streamable.py index 787be2a0fa0e..b6e47b154b48 100644 --- a/chia/util/streamable.py +++ b/chia/util/streamable.py @@ -216,7 +216,7 @@ def function_to_convert_one_item( elif hasattr(f_type, "from_json_dict"): if json_parser is None: json_parser = f_type.from_json_dict - return lambda item: json_parser(item) + return json_parser elif issubclass(f_type, bytes): # Type is bytes, data is a hex string or bytes return lambda item: convert_byte_type(f_type, item) diff --git a/chia/wallet/trade_manager.py b/chia/wallet/trade_manager.py index 1f64f406f422..5cb2cc02836f 100644 --- a/chia/wallet/trade_manager.py +++ b/chia/wallet/trade_manager.py @@ -1033,8 +1033,7 @@ async def check_for_final_modifications( if WalletType(wallet.type()) == WalletType.VC: assert isinstance(wallet, VCWallet) return await wallet.add_vc_authorization(offer, solver, action_scope) - else: - raise ValueError("No VCs to approve CR-CATs with") # pragma: no cover + raise ValueError("No VCs to approve CR-CATs with") # pragma: no cover return offer, Solver({}) diff --git a/chia/wallet/trading/offer.py b/chia/wallet/trading/offer.py index 3aa58fdc94d7..5a8e6ec066dc 100644 --- a/chia/wallet/trading/offer.py +++ b/chia/wallet/trading/offer.py @@ -326,11 +326,11 @@ def summary(self) -> tuple[dict[str, int], dict[str, int], dict[str, dict[str, A def keys_to_strings(dic: dict[Optional[bytes32], Any]) -> dict[str, Any]: new_dic: dict[str, Any] = {} - for key in dic: + for key, val in dic.items(): if key is None: - new_dic["xch"] = dic[key] + new_dic["xch"] = val else: - new_dic[key.hex()] = dic[key] + new_dic[key.hex()] = val return new_dic driver_dict: dict[str, Any] = {} diff --git a/chia/wallet/transaction_record.py b/chia/wallet/transaction_record.py index 8fb0d71cc0a3..5ccbdb551fec 100644 --- a/chia/wallet/transaction_record.py +++ b/chia/wallet/transaction_record.py @@ -67,7 +67,7 @@ def is_in_mempool(self) -> bool: def height_farmed(self, genesis_challenge: bytes32) -> Optional[uint32]: if not self.confirmed: return None - if self.type == TransactionType.FEE_REWARD or self.type == TransactionType.COINBASE_REWARD: + if self.type in (TransactionType.FEE_REWARD, TransactionType.COINBASE_REWARD): for block_index in range(self.confirmed_at_height, self.confirmed_at_height - 100, -1): if block_index < 0: return None diff --git a/chia/wallet/wallet_state_manager.py b/chia/wallet/wallet_state_manager.py index 1cef6dee295e..d26ba2c20567 100644 --- a/chia/wallet/wallet_state_manager.py +++ b/chia/wallet/wallet_state_manager.py @@ -1692,10 +1692,9 @@ async def handle_vc(self, vc: VerifiedCredential) -> Optional[WalletIdentifier]: self.log.info(f"Found verified credential {vc.launcher_id.hex()}.") for wallet_info in await self.get_all_wallet_info_entries(wallet_type=WalletType.VC): return WalletIdentifier(wallet_info.id, WalletType.VC) - else: - # Create a new VC wallet - vc_wallet = await VCWallet.create_new_vc_wallet(self, self.main_wallet) # pragma: no cover - return WalletIdentifier(vc_wallet.id(), WalletType.VC) # pragma: no cover + # Create a new VC wallet + vc_wallet = await VCWallet.create_new_vc_wallet(self, self.main_wallet) # pragma: no cover + return WalletIdentifier(vc_wallet.id(), WalletType.VC) # pragma: no cover async def _add_coin_states( self, diff --git a/installhelper.py b/installhelper.py index 51de3f90bcbf..f6e2f9606d0d 100644 --- a/installhelper.py +++ b/installhelper.py @@ -55,7 +55,7 @@ def get_chia_version() -> str: chia_executable = shutil.which("chia") if chia_executable is None: chia_executable = "chia" - output = subprocess.run([chia_executable, "version"], capture_output=True) + output = subprocess.run([chia_executable, "version"], capture_output=True, check=False) if output.returncode == 0: version = str(output.stdout.strip(), "utf-8").splitlines()[-1] return make_semver(version) diff --git a/ruff.toml b/ruff.toml index d44603e9b421..1e37af422019 100644 --- a/ruff.toml +++ b/ruff.toml @@ -15,48 +15,36 @@ select = [ explicit-preview-rules = false ignore = [ # Pylint convention - "PLC0105", # type-name-incorrect-variance - "PLC0415", # import-outside-top-level - "PLC2801", # unnecessary-dunder-call - "PLC0206", # dict-index-missing-items - "PLC1901", # compare-to-empty-string - "PLC2701", # import-private-name - "PLC0414", # useless-import-alias + "PLC0105", # type-name-incorrect-variance (2) (?) + "PLC0415", # import-outside-top-level (286) (x) + "PLC2801", # unnecessary-dunder-call (11) (x) + "PLC1901", # compare-to-empty-string (51) (x) + "PLC2701", # import-private-name (24) (x) # Pylint refactor - "PLR0915", # too-many-statements - "PLR0914", # too-many-locals - "PLR0913", # too-many-arguments - "PLR0912", # too-many-branches - "PLR1702", # too-many-nested-blocks - "PLR0904", # too-many-public-methods - "PLR6301", # no-self-use - "PLR0917", # too-many-positional-arguments - "PLR6201", # literal-membership - "PLR0911", # too-many-return-statements - "PLR2004", # magic-value-comparison - "PLR1714", # repeated-equality-comparison - "PLR6104", # non-augmented-assignment - "PLR1704", # redefined-argument-from-local - "PLR0916", # too-many-boolean-expressions - "PLR5501", # collapsible-else-if - "PLR1711", # useless-return - "PLR1730", # if-stmt-min-max - "PLR1736", # unnecessary-list-index-lookup - "PLR1733", # unnecessary-dict-index-lookup + "PLR0915", # too-many-statements (222) (x) + "PLR0914", # too-many-locals (328) (x) + "PLR0913", # too-many-arguments (397) (x) + "PLR0912", # too-many-branches (193) (x) + "PLR1702", # too-many-nested-blocks (124) (x) + "PLR0904", # too-many-public-methods (47) (x) + "PLR0917", # too-many-positional-arguments (345) (x) + "PLR0916", # too-many-boolean-expressions (3) (x) + "PLR0911", # too-many-return-statements (52) (x) + "PLR6301", # no-self-use (699) (-) + "PLR6201", # literal-membership (86) (?) + "PLR2004", # magic-value-comparison (901) (-) + "PLR6104", # non-augmented-assignment (27) (?) + "PLR1704", # redefined-argument-from-local (13) (-) + "PLR5501", # collapsible-else-if (49) (?) + "PLR1711", # useless-return (14) (?) # Pylint warning - "PLW2901", # redefined-loop-name - "PLW1641", # eq-without-hash - "PLW1514", # unspecified-encoding - "PLW0602", # global-variable-not-assigned - "PLW0603", # global-statement - "PLW0108", # unnecessary-lambda - "PLW1510", # subprocess-run-without-check - "PLW0120", # useless-else-on-loop - - # Flake8 core - # "F841", # unused-variable (540) + "PLW2901", # redefined-loop-name (19) (-) + "PLW1641", # eq-without-hash (5) (?) + "PLW1514", # unspecified-encoding (69) (?) + "PLW0602", # global-variable-not-assigned (5) (?) + "PLW0603", # global-statement (9) (?) ] diff --git a/tools/chialispp.py b/tools/chialispp.py index 334b5e866f93..09f88f598883 100644 --- a/tools/chialispp.py +++ b/tools/chialispp.py @@ -151,7 +151,7 @@ def output_line(self) -> None: if semis == 0: # We've entered a string, stop processing - if ch == b"'" or ch == b'"': + if ch in (b"'", b'"'): in_string = ch continue elif ch == b"(":