From e6eb58f26c1a0214701c6a42753132c22f1e91bd Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 30 Oct 2024 13:20:39 -0700 Subject: [PATCH] Get flake8 config partially ready --- chia/_tests/conftest.py | 11 +---------- chia/_tests/core/test_full_node_rpc.py | 4 ++-- chia/_tests/generator/test_compression.py | 15 ++------------- chia/_tests/pools/test_pool_cmdline.py | 3 +-- chia/_tests/util/build_network_protocol_files.py | 10 +++++++--- chia/_tests/util/protocol_messages_json.py | 1 + chia/_tests/util/test_network_protocol_files.py | 1 + chia/_tests/util/test_network_protocol_json.py | 1 + chia/_tests/wallet/cat_wallet/test_cat_wallet.py | 4 ---- chia/plotting/check_plots.py | 4 ++-- chia/rpc/wallet_rpc_client.py | 1 - chia/util/streamable.py | 8 ++++---- pyproject.toml | 9 +++++++++ 13 files changed, 31 insertions(+), 41 deletions(-) diff --git a/chia/_tests/conftest.py b/chia/_tests/conftest.py index 010d93ccdfc2..4cff570eb200 100644 --- a/chia/_tests/conftest.py +++ b/chia/_tests/conftest.py @@ -1,8 +1,7 @@ -# flake8: noqa E402 # See imports after multiprocessing.set_start_method +# ruff: noqa: E402 # See imports after multiprocessing.set_start_method from __future__ import annotations import asyncio -import dataclasses import datetime import functools import json @@ -24,7 +23,6 @@ from _pytest.fixtures import SubRequest from pytest import MonkeyPatch -import chia._tests from chia._tests import ether from chia._tests.core.data_layer.util import ChiaRoot from chia._tests.core.node_height import node_height_at_least @@ -50,13 +48,10 @@ from chia._tests.util.spend_sim import CostLogger from chia._tests.util.time_out_assert import time_out_assert from chia.consensus.constants import ConsensusConstants -from chia.full_node.full_node import FullNode from chia.full_node.full_node_api import FullNodeAPI from chia.rpc.farmer_rpc_client import FarmerRpcClient from chia.rpc.harvester_rpc_client import HarvesterRpcClient from chia.rpc.wallet_rpc_client import WalletRpcClient -from chia.seeder.crawler import Crawler -from chia.seeder.crawler_api import CrawlerAPI from chia.seeder.dns_server import DNSServer from chia.server.server import ChiaServer from chia.server.start_service import Service @@ -71,13 +66,10 @@ ) from chia.simulator.start_simulator import SimulatorFullNodeService from chia.simulator.wallet_tools import WalletTool -from chia.timelord.timelord import Timelord -from chia.timelord.timelord_api import TimelordAPI # Set spawn after stdlib imports, but before other imports from chia.types.aliases import ( CrawlerService, - DataLayerService, FarmerService, FullNodeService, HarvesterService, @@ -92,7 +84,6 @@ from chia.util.task_timing import main as task_instrumentation_main from chia.util.task_timing import start_task_instrumentation, stop_task_instrumentation from chia.wallet.wallet_node import WalletNode -from chia.wallet.wallet_node_api import WalletNodeAPI multiprocessing.set_start_method("spawn") diff --git a/chia/_tests/core/test_full_node_rpc.py b/chia/_tests/core/test_full_node_rpc.py index a91de8854468..c8d29e26f52f 100644 --- a/chia/_tests/core/test_full_node_rpc.py +++ b/chia/_tests/core/test_full_node_rpc.py @@ -713,7 +713,7 @@ async def test_coin_name_not_found_in_mempool(one_node, self_hostname): empty_coin_name = bytes32.zeros mempool_item = await client.get_mempool_items_by_coin_name(empty_coin_name) - assert mempool_item["success"] == True + assert mempool_item["success"] assert "mempool_items" in mempool_item assert len(mempool_item["mempool_items"]) == 0 finally: @@ -780,7 +780,7 @@ async def test_coin_name_found_in_mempool(one_node, self_hostname): mempool_item = await client.get_mempool_items_by_coin_name(coin_to_spend.name()) # found coin in coin spends - assert mempool_item["success"] == True + assert mempool_item["success"] assert "mempool_items" in mempool_item assert len(mempool_item["mempool_items"]) > 0 for item in mempool_item["mempool_items"]: diff --git a/chia/_tests/generator/test_compression.py b/chia/_tests/generator/test_compression.py index e313c942f9be..860697547c9a 100644 --- a/chia/_tests/generator/test_compression.py +++ b/chia/_tests/generator/test_compression.py @@ -1,24 +1,15 @@ -# flake8: noqa: F501 +# ruff: noqa: E501 from __future__ import annotations import io -from dataclasses import dataclass from typing import Any -import pytest -from chia_rs import ALLOW_BACKREFS +from chia_rs import serialized_length from clvm.serialize import sexp_from_stream from clvm.SExp import SExp from clvm_tools import binutils -from chia._tests.core.make_block_generator import make_spend_bundle -from chia._tests.generator.test_rom import run_generator -from chia.full_node.bundle_tools import simple_solution_generator, simple_solution_generator_backrefs -from chia.full_node.mempool_check_conditions import get_puzzle_and_solution_for_coin -from chia.simulator.block_tools import test_constants from chia.types.blockchain_format.program import INFINITE_COST, Program -from chia.types.blockchain_format.serialized_program import SerializedProgram -from chia.types.generator_types import BlockGenerator from chia.types.spend_bundle import SpendBundle from chia.util.byte_types import hexstr_to_bytes from chia.util.ints import uint32 @@ -51,8 +42,6 @@ FAKE_BLOCK_HEIGHT1 = uint32(100) FAKE_BLOCK_HEIGHT2 = uint32(200) -from chia_rs import serialized_length - assert serialized_length(original_generator) == len(original_generator) assert serialized_length(gen1) == len(gen1) assert serialized_length(gen2) == len(gen2) diff --git a/chia/_tests/pools/test_pool_cmdline.py b/chia/_tests/pools/test_pool_cmdline.py index 2ab6e363f06f..73f3d7d01558 100644 --- a/chia/_tests/pools/test_pool_cmdline.py +++ b/chia/_tests/pools/test_pool_cmdline.py @@ -2,9 +2,8 @@ from __future__ import annotations -import click import pytest -from click.testing import CliRunner, Result +from click.testing import CliRunner from chia.cmds.plotnft import create_cmd, show_cmd diff --git a/chia/_tests/util/build_network_protocol_files.py b/chia/_tests/util/build_network_protocol_files.py index 1b5c324a344f..c81f748fcfd3 100644 --- a/chia/_tests/util/build_network_protocol_files.py +++ b/chia/_tests/util/build_network_protocol_files.py @@ -1,3 +1,4 @@ +# ruff: noqa: F405 from __future__ import annotations import os @@ -183,7 +184,8 @@ def visitor(obj: Any, name: str) -> None: def build_protocol_test() -> str: - result = """# this file is generated by build_network_protocol_files.py + result = """# ruff: noqa: F405 +# this file is generated by build_network_protocol_files.py from __future__ import annotations @@ -232,7 +234,8 @@ def visitor(obj: Any, name: str) -> None: def get_protocol_json() -> str: - result = """# this file is generated by build_network_protocol_files.py + result = """# ruff: noqa: E501 +# this file is generated by build_network_protocol_files.py from __future__ import annotations from typing import Any @@ -251,7 +254,8 @@ def visitor(obj: Any, name: str) -> None: def build_json_test() -> str: - result = """# this file is generated by build_network_protocol_files.py + result = """# ruff: noqa: F405 +# this file is generated by build_network_protocol_files.py from __future__ import annotations diff --git a/chia/_tests/util/protocol_messages_json.py b/chia/_tests/util/protocol_messages_json.py index 6aa5800fc207..dbc48e209290 100644 --- a/chia/_tests/util/protocol_messages_json.py +++ b/chia/_tests/util/protocol_messages_json.py @@ -1,3 +1,4 @@ +# ruff: noqa: E501 # this file is generated by build_network_protocol_files.py from __future__ import annotations diff --git a/chia/_tests/util/test_network_protocol_files.py b/chia/_tests/util/test_network_protocol_files.py index 5066af6e3750..0742e05bb71d 100644 --- a/chia/_tests/util/test_network_protocol_files.py +++ b/chia/_tests/util/test_network_protocol_files.py @@ -1,3 +1,4 @@ +# ruff: noqa: F405 # this file is generated by build_network_protocol_files.py from __future__ import annotations diff --git a/chia/_tests/util/test_network_protocol_json.py b/chia/_tests/util/test_network_protocol_json.py index d68571a3bde9..3acb9240a83e 100644 --- a/chia/_tests/util/test_network_protocol_json.py +++ b/chia/_tests/util/test_network_protocol_json.py @@ -1,3 +1,4 @@ +# ruff: noqa: F405 # this file is generated by build_network_protocol_files.py from __future__ import annotations diff --git a/chia/_tests/wallet/cat_wallet/test_cat_wallet.py b/chia/_tests/wallet/cat_wallet/test_cat_wallet.py index dae615e4bb8e..ea22288f84bd 100644 --- a/chia/_tests/wallet/cat_wallet/test_cat_wallet.py +++ b/chia/_tests/wallet/cat_wallet/test_cat_wallet.py @@ -389,7 +389,6 @@ async def test_cat_spend(wallet_environments: WalletTestFramework) -> None: "cat": { "confirmed_wallet_balance": 60, "unconfirmed_wallet_balance": 60, - "pending_coin_removal_count": 0, "spendable_balance": 60, "max_send_amount": 60, "pending_change": 0, @@ -674,7 +673,6 @@ async def test_cat_doesnt_see_eve(wallet_environments: WalletTestFramework) -> N "cat": { "confirmed_wallet_balance": 60, "unconfirmed_wallet_balance": 60, - "pending_coin_removal_count": 0, "spendable_balance": 60, "max_send_amount": 60, "pending_change": 0, @@ -866,7 +864,6 @@ async def test_cat_spend_multiple(wallet_environments: WalletTestFramework) -> N "cat": { "confirmed_wallet_balance": 60, "unconfirmed_wallet_balance": 60, - "pending_coin_removal_count": 0, "spendable_balance": 60, "max_send_amount": 60, "pending_change": 0, @@ -892,7 +889,6 @@ async def test_cat_spend_multiple(wallet_environments: WalletTestFramework) -> N "cat": { "confirmed_wallet_balance": 20, "unconfirmed_wallet_balance": 20, - "pending_coin_removal_count": 0, "spendable_balance": 20, "max_send_amount": 20, "pending_change": 0, diff --git a/chia/plotting/check_plots.py b/chia/plotting/check_plots.py index 0b4cae105a87..d52bcbb8ea37 100644 --- a/chia/plotting/check_plots.py +++ b/chia/plotting/check_plots.py @@ -161,8 +161,8 @@ def process_plot(plot_path: Path, plot_info: PlotInfo, num_start: int, num_end: if plot_info.pool_contract_puzzle_hash is not None: pca: str = encode_puzzle_hash(plot_info.pool_contract_puzzle_hash, address_prefix) log.info(f"\t{'Pool contract address:':<23} {pca}") - log.info(f"\t{'Farmer public key:' :<23} {farmer_public_key}") - log.info(f"\t{'Local sk:' :<23} {local_sk}") + log.info(f"\t{'Farmer public key:':<23} {farmer_public_key}") + log.info(f"\t{'Local sk:':<23} {local_sk}") total_proofs = 0 caught_exception: bool = False diff --git a/chia/rpc/wallet_rpc_client.py b/chia/rpc/wallet_rpc_client.py index 980a3bec4078..02fc08284162 100644 --- a/chia/rpc/wallet_rpc_client.py +++ b/chia/rpc/wallet_rpc_client.py @@ -961,7 +961,6 @@ async def cancel_offers( { "secure": secure, "batch_fee": batch_fee, - "secure": secure, "batch_size": batch_size, "cancel_all": cancel_all, "asset_id": None if asset_id is None else asset_id.hex(), diff --git a/chia/util/streamable.py b/chia/util/streamable.py index 3b4684789185..787be2a0fa0e 100644 --- a/chia/util/streamable.py +++ b/chia/util/streamable.py @@ -112,7 +112,7 @@ def create_fields(cls: type[DataclassInstance]) -> StreamableFields: def is_type_List(f_type: object) -> bool: - return get_origin(f_type) == list or f_type == list + return get_origin(f_type) is list or f_type is list def is_type_SpecificOptional(f_type: object) -> bool: @@ -123,7 +123,7 @@ def is_type_SpecificOptional(f_type: object) -> bool: def is_type_Tuple(f_type: object) -> bool: - return get_origin(f_type) == tuple or f_type == tuple + return get_origin(f_type) is tuple or f_type is tuple def convert_optional(convert_func: ConvertFunctionType, item: Any) -> Any: @@ -389,7 +389,7 @@ def function_to_parse_one_item(f_type: type[Any]) -> ParseFunctionType: if hasattr(f_type, "parse"): # Ignoring for now as the proper solution isn't obvious return f_type.parse # type: ignore[no-any-return] - if f_type == bytes: + if f_type is bytes: return parse_bytes if is_type_List(f_type): inner_type = get_args(f_type)[0] @@ -453,7 +453,7 @@ def function_to_stream_one_item(f_type: type[Any]) -> StreamFunctionType: inner_type = get_args(f_type)[0] stream_inner_type_func = function_to_stream_one_item(inner_type) return lambda item, f: stream_optional(stream_inner_type_func, item, f) - elif f_type == bytes: + elif f_type is bytes: return stream_bytes elif hasattr(f_type, "stream"): return stream_streamable diff --git a/pyproject.toml b/pyproject.toml index 6f2b5114f013..0bcbfd0a78ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -168,6 +168,10 @@ select = [ "I", # Isort "FA", # Flake8: future-annotations "UP", # Pyupgrade + # Flake8 core + "F", + "E", + "W", ] explicit-preview-rules = false ignore = [ @@ -211,8 +215,13 @@ ignore = [ "PLW0108", # unnecessary-lambda "PLW1510", # subprocess-run-without-check "PLW0120", # useless-else-on-loop + + # Flake8 core + "E226", # missing-whitespace-around-arithmetic-operator + "F841", # unused-variable (540) ] + [tool.ruff.lint.isort] required-imports = ["from __future__ import annotations"]