Add missing type annotations and remove 10 mypy exclusions (#20582)

* Add missing type annotations and remove 10 mypy exclusions

Add return type annotations, parameter types, and generic type
parameters to 10 modules that had trivial mypy strict-mode violations
(1-2 errors each). Remove them from mypy-exclusions.txt so they are
now covered by strict type checking.

Modules fixed:
- chia.cmds.start_funcs (Popen generic param)
- chia.wallet.wallet_pool_store (classmethod return type)
- installhelper (return type)
- chia._tests.blockchain.blockchain_test_utils (return type)
- chia._tests.core.test_daemon_rpc (param + return types)
- chia._tests.core.test_filter (param + return types)
- chia._tests.pools.test_pool_config (param + return types)
- chia._tests.core.custom_types.test_coin (return types)
- chia._tests.core.util.test_lru_cache (return type + var annotation)
- chia._tests.core.util.test_significant_bits (return types)

Also fixes int-to-uint32 arg-type errors in test_wallet_pool_store.py
that surfaced once wallet_pool_store.py became strictly typed.

* Some better types and await ws_server.stop().

---------

Co-authored-by: Amine Khaldi <amine.khaldi@reactos.org>
This commit is contained in:
Zachary Brown
2026-03-03 13:47:24 -06:00
committed by GitHub
co-authored by Amine Khaldi
parent e2c3f1dea9
commit 2c5322a62b
12 changed files with 32 additions and 37 deletions
@@ -12,7 +12,7 @@ from chia.types.validation_state import ValidationState
from chia.util.errors import Err from chia.util.errors import Err
async def check_block_store_invariant(bc: Blockchain): async def check_block_store_invariant(bc: Blockchain) -> None:
db_wrapper = bc.block_store.db_wrapper db_wrapper = bc.block_store.db_wrapper
if db_wrapper.db_version == 1: if db_wrapper.db_version == 1:
+2 -2
View File
@@ -8,7 +8,7 @@ from chia.types.blockchain_format.coin import Coin
from chia.util.hash import std_hash from chia.util.hash import std_hash
def coin_serialize(amount: uint64, clvm_serialize: bytes, full_serialize: bytes): def coin_serialize(amount: uint64, clvm_serialize: bytes, full_serialize: bytes) -> None:
c = Coin(bytes32(b"a" * 32), bytes32(b"b" * 32), amount) c = Coin(bytes32(b"a" * 32), bytes32(b"b" * 32), amount)
expected_hash = (b"a" * 32) + (b"b" * 32) + clvm_serialize expected_hash = (b"a" * 32) + (b"b" * 32) + clvm_serialize
@@ -23,7 +23,7 @@ def coin_serialize(amount: uint64, clvm_serialize: bytes, full_serialize: bytes)
assert c2 == c assert c2 == c
def test_serialization(): def test_serialization() -> None:
coin_serialize(uint64(0xFFFF), bytes([0, 0xFF, 0xFF]), bytes([0, 0, 0, 0, 0, 0, 0xFF, 0xFF])) coin_serialize(uint64(0xFFFF), bytes([0, 0xFF, 0xFF]), bytes([0, 0, 0, 0, 0, 0, 0xFF, 0xFF]))
coin_serialize(uint64(1337000000), bytes([0x4F, 0xB1, 0x00, 0x40]), bytes([0, 0, 0, 0, 0x4F, 0xB1, 0x00, 0x40])) coin_serialize(uint64(1337000000), bytes([0x4F, 0xB1, 0x00, 0x40]), bytes([0, 0, 0, 0, 0x4F, 0xB1, 0x00, 0x40]))
+4 -2
View File
@@ -4,10 +4,12 @@ import pytest
from chia import __version__ from chia import __version__
from chia.daemon.client import connect_to_daemon from chia.daemon.client import connect_to_daemon
from chia.daemon.server import WebSocketServer
from chia.simulator.block_tools import BlockTools
@pytest.mark.anyio @pytest.mark.anyio
async def test_get_version_rpc(get_daemon, bt): async def test_get_version_rpc(get_daemon: WebSocketServer, bt: BlockTools) -> None:
ws_server = get_daemon ws_server = get_daemon
config = bt.config config = bt.config
client = await connect_to_daemon( client = await connect_to_daemon(
@@ -21,4 +23,4 @@ async def test_get_version_rpc(get_daemon, bt):
assert response["data"]["success"] assert response["data"]["success"]
assert response["data"]["version"] == __version__ assert response["data"]["version"] == __version__
ws_server.stop() await ws_server.stop()
+2 -1
View File
@@ -3,11 +3,12 @@ from __future__ import annotations
import pytest import pytest
from chiabip158 import PyBIP158 from chiabip158 import PyBIP158
from chia._tests.util.setup_nodes import OldSimulatorsAndWallets
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
@pytest.mark.anyio @pytest.mark.anyio
async def test_basic_filter_test(simulator_and_wallet): async def test_basic_filter_test(simulator_and_wallet: OldSimulatorsAndWallets) -> None:
_full_nodes, wallets, bt = simulator_and_wallet _full_nodes, wallets, bt = simulator_and_wallet
wallet_node, _server_2 = wallets[0] wallet_node, _server_2 = wallets[0]
wallet = wallet_node.wallet_state_manager.main_wallet wallet = wallet_node.wallet_state_manager.main_wallet
+2 -2
View File
@@ -8,8 +8,8 @@ from chia.util.lru_cache import LRUCache, LRUSet
class TestLRUCache(unittest.TestCase): class TestLRUCache(unittest.TestCase):
def test_lru_cache(self): def test_lru_cache(self) -> None:
cache = LRUCache(5) cache: LRUCache[bytes, int] = LRUCache(5)
assert cache.get(b"0") is None assert cache.get(b"0") is None
@@ -6,7 +6,7 @@ from chia.util.significant_bits import count_significant_bits, truncate_to_signi
class TestSignificantBits(unittest.TestCase): class TestSignificantBits(unittest.TestCase):
def test_truncate_to_significant_bits(self): def test_truncate_to_significant_bits(self) -> None:
a = -0b001101 a = -0b001101
assert truncate_to_significant_bits(a, 2) == -0b1100 assert truncate_to_significant_bits(a, 2) == -0b1100
a = -0b001111 a = -0b001111
@@ -26,7 +26,7 @@ class TestSignificantBits(unittest.TestCase):
a = 0b10101 a = 0b10101
assert truncate_to_significant_bits(a, 4) == 0b10100 assert truncate_to_significant_bits(a, 4) == 0b10100
def test_count_significant_bits(self): def test_count_significant_bits(self) -> None:
assert count_significant_bits(0b0001) == 1 assert count_significant_bits(0b0001) == 1
assert count_significant_bits(0b00010) == 1 assert count_significant_bits(0b00010) == 1
assert count_significant_bits(0b01010) == 3 assert count_significant_bits(0b01010) == 3
+3 -1
View File
@@ -1,10 +1,12 @@
from __future__ import annotations from __future__ import annotations
from pathlib import Path
from chia.pools.pool_config import PoolWalletConfig from chia.pools.pool_config import PoolWalletConfig
from chia.util.config import create_default_chia_config, load_config, lock_config, save_config from chia.util.config import create_default_chia_config, load_config, lock_config, save_config
def test_pool_config(tmp_path): def test_pool_config(tmp_path: Path) -> None:
test_root = tmp_path test_root = tmp_path
test_path = test_root / "config" test_path = test_root / "config"
eg_config = test_path / "config.yaml" eg_config = test_path / "config.yaml"
+13 -13
View File
@@ -79,15 +79,15 @@ class TestWalletPoolStore:
assert await store.get_spends_for_wallet(0) == [] assert await store.get_spends_for_wallet(0) == []
assert await store.get_spends_for_wallet(1) == [] assert await store.get_spends_for_wallet(1) == []
await store.add_spend(1, solution_1, 100) await store.add_spend(1, solution_1, uint32(100))
assert await store.get_spends_for_wallet(1) == [(100, solution_1)] assert await store.get_spends_for_wallet(1) == [(100, solution_1)]
# Idempotent # Idempotent
await store.add_spend(1, solution_1, 100) await store.add_spend(1, solution_1, uint32(100))
assert await store.get_spends_for_wallet(1) == [(100, solution_1)] assert await store.get_spends_for_wallet(1) == [(100, solution_1)]
with pytest.raises(ValueError): with pytest.raises(ValueError):
await store.add_spend(1, solution_1, 101) await store.add_spend(1, solution_1, uint32(101))
# Rebuild cache, no longer present # Rebuild cache, no longer present
raise RuntimeError("abandon transaction") raise RuntimeError("abandon transaction")
@@ -96,26 +96,26 @@ class TestWalletPoolStore:
assert await store.get_spends_for_wallet(1) == [] assert await store.get_spends_for_wallet(1) == []
await store.add_spend(1, solution_1, 100) await store.add_spend(1, solution_1, uint32(100))
assert await store.get_spends_for_wallet(1) == [(100, solution_1)] assert await store.get_spends_for_wallet(1) == [(100, solution_1)]
solution_1_alt: CoinSpend = make_child_solution(solution_0_alt, new_coin=None, seeded_random=seeded_random) solution_1_alt: CoinSpend = make_child_solution(solution_0_alt, new_coin=None, seeded_random=seeded_random)
with pytest.raises(ValueError): with pytest.raises(ValueError):
await store.add_spend(1, solution_1_alt, 100) await store.add_spend(1, solution_1_alt, uint32(100))
assert await store.get_spends_for_wallet(1) == [(100, solution_1)] assert await store.get_spends_for_wallet(1) == [(100, solution_1)]
solution_2: CoinSpend = make_child_solution(solution_1, new_coin=None, seeded_random=seeded_random) solution_2: CoinSpend = make_child_solution(solution_1, new_coin=None, seeded_random=seeded_random)
await store.add_spend(1, solution_2, 100) await store.add_spend(1, solution_2, uint32(100))
solution_3: CoinSpend = make_child_solution(solution_2, new_coin=None, seeded_random=seeded_random) solution_3: CoinSpend = make_child_solution(solution_2, new_coin=None, seeded_random=seeded_random)
await store.add_spend(1, solution_3, 100) await store.add_spend(1, solution_3, uint32(100))
solution_4: CoinSpend = make_child_solution(solution_3, new_coin=None, seeded_random=seeded_random) solution_4: CoinSpend = make_child_solution(solution_3, new_coin=None, seeded_random=seeded_random)
with pytest.raises(ValueError): with pytest.raises(ValueError):
await store.add_spend(1, solution_4, 99) await store.add_spend(1, solution_4, uint32(99))
await store.add_spend(1, solution_4, 101) await store.add_spend(1, solution_4, uint32(101))
await store.rollback(101, 1) await store.rollback(101, 1)
assert await store.get_spends_for_wallet(1) == [ assert await store.get_spends_for_wallet(1) == [
(100, solution_1), (100, solution_1),
@@ -130,11 +130,11 @@ class TestWalletPoolStore:
(100, solution_3), (100, solution_3),
] ]
with pytest.raises(ValueError): with pytest.raises(ValueError):
await store.add_spend(1, solution_1, 105) await store.add_spend(1, solution_1, uint32(105))
await store.add_spend(1, solution_4, 105) await store.add_spend(1, solution_4, uint32(105))
solution_5: CoinSpend = make_child_solution(solution_4, new_coin=None, seeded_random=seeded_random) solution_5: CoinSpend = make_child_solution(solution_4, new_coin=None, seeded_random=seeded_random)
await store.add_spend(1, solution_5, 105) await store.add_spend(1, solution_5, uint32(105))
await store.rollback(99, 1) await store.rollback(99, 1)
assert await store.get_spends_for_wallet(1) == [] assert await store.get_spends_for_wallet(1) == []
@@ -155,5 +155,5 @@ async def test_delete_wallet(seeded_random: random.Random) -> None:
for wallet_id, spends in dummy_spends.spends_per_wallet.items(): for wallet_id, spends in dummy_spends.spends_per_wallet.items():
# Assert the existence again here to make sure the previous removals did not affect other wallet_ids # Assert the existence again here to make sure the previous removals did not affect other wallet_ids
await assert_db_spends(store, wallet_id, spends) await assert_db_spends(store, wallet_id, spends)
await store.delete_wallet(wallet_id) await store.delete_wallet(uint32(wallet_id))
await assert_db_spends(store, wallet_id, []) await assert_db_spends(store, wallet_id, [])
+1 -1
View File
@@ -16,7 +16,7 @@ from chia.util.keychain import Keychain
from chia.util.service_groups import services_for_groups from chia.util.service_groups import services_for_groups
def launch_start_daemon(root_path: Path) -> subprocess.Popen: def launch_start_daemon(root_path: Path) -> subprocess.Popen[bytes]:
os.environ["CHIA_ROOT"] = str(root_path) os.environ["CHIA_ROOT"] = str(root_path)
creationflags = 0 creationflags = 0
if sys.platform == "win32": if sys.platform == "win32":
+1 -1
View File
@@ -14,7 +14,7 @@ class WalletPoolStore:
db_wrapper: DBWrapper2 db_wrapper: DBWrapper2
@classmethod @classmethod
async def create(cls, wrapper: DBWrapper2): async def create(cls, wrapper: DBWrapper2) -> WalletPoolStore:
self = cls() self = cls()
self.db_wrapper = wrapper self.db_wrapper = wrapper
+1 -1
View File
@@ -61,7 +61,7 @@ def get_chia_version() -> str:
return make_semver(version) return make_semver(version)
def update_version(package_json_path: str): def update_version(package_json_path: str) -> None:
if not exists(package_json_path): if not exists(package_json_path):
return return
-10
View File
@@ -1,5 +1,4 @@
# File created by: python manage-mypy.py build-exclusions # File created by: python manage-mypy.py build-exclusions
chia.cmds.start_funcs
chia.daemon.server chia.daemon.server
chia.introducer.introducer chia.introducer.introducer
chia.introducer.introducer_api chia.introducer.introducer_api
@@ -32,12 +31,9 @@ chia.wallet.util.new_peak_queue
chia.wallet.wallet_coin_store chia.wallet.wallet_coin_store
chia.wallet.wallet_interested_store chia.wallet.wallet_interested_store
chia.wallet.wallet_node_api chia.wallet.wallet_node_api
chia.wallet.wallet_pool_store
chia.wallet.wallet_puzzle_store chia.wallet.wallet_puzzle_store
chia.wallet.wallet_transaction_store chia.wallet.wallet_transaction_store
chia.wallet.wallet_user_store chia.wallet.wallet_user_store
installhelper
chia._tests.blockchain.blockchain_test_utils
chia._tests.build-init-files chia._tests.build-init-files
chia._tests.clvm.coin_store chia._tests.clvm.coin_store
chia._tests.clvm.test_chialisp_deserialization chia._tests.clvm.test_chialisp_deserialization
@@ -50,7 +46,6 @@ chia._tests.conftest
chia._tests.connection_utils chia._tests.connection_utils
chia._tests.core.cmds.test_keys chia._tests.core.cmds.test_keys
chia._tests.core.consensus.test_pot_iterations chia._tests.core.consensus.test_pot_iterations
chia._tests.core.custom_types.test_coin
chia._tests.core.custom_types.test_spend_bundle chia._tests.core.custom_types.test_spend_bundle
chia._tests.core.daemon.test_daemon chia._tests.core.daemon.test_daemon
chia._tests.core.full_node.stores.test_sync_store chia._tests.core.full_node.stores.test_sync_store
@@ -60,18 +55,13 @@ chia._tests.core.full_node.test_performance
chia._tests.core.full_node.test_transactions chia._tests.core.full_node.test_transactions
chia._tests.core.ssl.test_ssl chia._tests.core.ssl.test_ssl
chia._tests.core.test_crawler_rpc chia._tests.core.test_crawler_rpc
chia._tests.core.test_daemon_rpc
chia._tests.core.test_db_conversion chia._tests.core.test_db_conversion
chia._tests.core.test_filter
chia._tests.core.util.test_config chia._tests.core.util.test_config
chia._tests.core.util.test_file_keyring_synchronization chia._tests.core.util.test_file_keyring_synchronization
chia._tests.core.util.test_files chia._tests.core.util.test_files
chia._tests.core.util.test_keychain chia._tests.core.util.test_keychain
chia._tests.core.util.test_keyring_wrapper chia._tests.core.util.test_keyring_wrapper
chia._tests.core.util.test_lru_cache
chia._tests.core.util.test_significant_bits
chia._tests.plotting.test_plot_manager chia._tests.plotting.test_plot_manager
chia._tests.pools.test_pool_config
chia._tests.pools.test_pool_puzzles_lifecycle chia._tests.pools.test_pool_puzzles_lifecycle
chia._tests.pools.test_wallet_pool_store chia._tests.pools.test_wallet_pool_store
chia._tests.simulation.test_simulation chia._tests.simulation.test_simulation