Skip to content

Commit

Permalink
Get flake8 config partially ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Quexington committed Oct 30, 2024
1 parent 84d9f40 commit e6eb58f
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 41 deletions.
11 changes: 1 addition & 10 deletions chia/_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions chia/_tests/core/test_full_node_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"]:
Expand Down
15 changes: 2 additions & 13 deletions chia/_tests/generator/test_compression.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions chia/_tests/pools/test_pool_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions chia/_tests/util/build_network_protocol_files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: F405
from __future__ import annotations

import os
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions chia/_tests/util/protocol_messages_json.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: E501
# this file is generated by build_network_protocol_files.py
from __future__ import annotations

Expand Down
1 change: 1 addition & 0 deletions chia/_tests/util/test_network_protocol_files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: F405
# this file is generated by build_network_protocol_files.py

from __future__ import annotations
Expand Down
1 change: 1 addition & 0 deletions chia/_tests/util/test_network_protocol_json.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: F405
# this file is generated by build_network_protocol_files.py

from __future__ import annotations
Expand Down
4 changes: 0 additions & 4 deletions chia/_tests/wallet/cat_wallet/test_cat_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions chia/plotting/check_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion chia/rpc/wallet_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions chia/util/streamable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ select = [
"I", # Isort
"FA", # Flake8: future-annotations
"UP", # Pyupgrade
# Flake8 core
"F",
"E",
"W",
]
explicit-preview-rules = false
ignore = [
Expand Down Expand Up @@ -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"]

Expand Down

0 comments on commit e6eb58f

Please sign in to comment.