Enable mypy on almost every cli file.

This commit is contained in:
Jack Nelson 2023-07-03 22:57:41 -04:00
parent c8ebdc4929
commit 063cc8ee99
No known key found for this signature in database
GPG Key ID: 63C8D6E673ADF88B
6 changed files with 30 additions and 32 deletions

View File

@ -12,7 +12,7 @@ from chia.plotting.util import add_plot_directory, validate_plot_size
log = logging.getLogger(__name__)
def show_plots(root_path: Path):
def show_plots(root_path: Path) -> None:
from chia.plotting.util import get_plot_directories
print("Directories where plots are being searched for:")
@ -29,7 +29,7 @@ def show_plots(root_path: Path):
@click.group("plots", help="Manage your plots")
@click.pass_context
def plots_cmd(ctx: click.Context):
def plots_cmd(ctx: click.Context) -> None:
"""Create, add, remove and check your plots"""
from chia.util.chia_logging import initialize_logging
@ -114,7 +114,7 @@ def create_cmd(
nobitfield: bool,
exclude_final_dir: bool,
connect_to_daemon: bool,
):
) -> None:
from chia.plotting.create_plots import create_plots, resolve_plot_keys
from chia.plotting.util import Params
@ -174,7 +174,7 @@ def create_cmd(
@click.pass_context
def check_cmd(
ctx: click.Context, num: int, grep_string: str, list_duplicates: bool, debug_show_memo: bool, challenge_start: int
):
) -> None:
from chia.plotting.check_plots import check_plots
check_plots(ctx.obj["root_path"], num, challenge_start, grep_string, list_duplicates, debug_show_memo)
@ -190,7 +190,7 @@ def check_cmd(
show_default=True,
)
@click.pass_context
def add_cmd(ctx: click.Context, final_dir: str):
def add_cmd(ctx: click.Context, final_dir: str) -> None:
from chia.plotting.util import add_plot_directory
try:
@ -210,7 +210,7 @@ def add_cmd(ctx: click.Context, final_dir: str):
show_default=True,
)
@click.pass_context
def remove_cmd(ctx: click.Context, final_dir: str):
def remove_cmd(ctx: click.Context, final_dir: str) -> None:
from chia.plotting.util import remove_plot_directory
remove_plot_directory(ctx.obj["root_path"], final_dir)
@ -218,5 +218,5 @@ def remove_cmd(ctx: click.Context, final_dir: str):
@plots_cmd.command("show", help="Shows the directory of current plots")
@click.pass_context
def show_cmd(ctx: click.Context):
def show_cmd(ctx: click.Context) -> None:
show_plots(ctx.obj["root_path"])

View File

@ -13,5 +13,5 @@ from chia.plotters.plotters import call_plotters
)
@click.pass_context
@click.argument("args", nargs=-1)
def plotters_cmd(ctx: click.Context, args):
def plotters_cmd(ctx: click.Context, args: tuple[click.Argument]) -> None:
call_plotters(ctx.obj["root_path"], args)

View File

@ -267,7 +267,7 @@ def show_cmd(wallet_rpc_port: Optional[int], fingerprint: int, wallet_type: Opti
is_flag=True,
default=False,
)
def get_address_cmd(wallet_rpc_port: Optional[int], id, fingerprint: int, new_address: bool) -> None:
def get_address_cmd(wallet_rpc_port: Optional[int], id: int, fingerprint: int, new_address: bool) -> None:
from .wallet_funcs import get_address
asyncio.run(get_address(wallet_rpc_port, fingerprint, id, new_address))
@ -298,7 +298,9 @@ def get_address_cmd(wallet_rpc_port: Optional[int], id, fingerprint: int, new_ad
@click.option(
"-m", "--fee", help="A fee to add to the offer when it gets taken, in XCH", default="0", show_default=True
)
def clawback(wallet_rpc_port: Optional[int], id, fingerprint: int, tx_ids: str, fee: str) -> None: # pragma: no cover
def clawback(
wallet_rpc_port: Optional[int], id: int, fingerprint: int, tx_ids: str, fee: str
) -> None: # pragma: no cover
from .wallet_funcs import spend_clawback
asyncio.run(spend_clawback(wallet_rpc_port, fingerprint, Decimal(fee), tx_ids)) # Wallet ID is not Used.
@ -314,7 +316,7 @@ def clawback(wallet_rpc_port: Optional[int], id, fingerprint: int, tx_ids: str,
)
@click.option("-i", "--id", help="Id of the wallet to use", type=int, default=1, show_default=True, required=True)
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int)
def delete_unconfirmed_transactions_cmd(wallet_rpc_port: Optional[int], id, fingerprint: int) -> None:
def delete_unconfirmed_transactions_cmd(wallet_rpc_port: Optional[int], id: int, fingerprint: int) -> None:
from .wallet_funcs import delete_unconfirmed_transactions
asyncio.run(delete_unconfirmed_transactions(wallet_rpc_port, fingerprint, id))
@ -571,7 +573,7 @@ def check_wallet_cmd(ctx: click.Context, db_path: str, verbose: bool) -> None:
@wallet_cmd.group("did", help="DID related actions")
def did_cmd():
def did_cmd() -> None:
pass
@ -848,7 +850,7 @@ def did_transfer_did(
@wallet_cmd.group("nft", help="NFT related actions")
def nft_cmd():
def nft_cmd() -> None:
pass
@ -1174,7 +1176,7 @@ wallet_cmd.add_command(coins_cmd)
@wallet_cmd.group("notifications", help="Send/Manage notifications")
def notification_cmd():
def notification_cmd() -> None:
pass
@ -1259,7 +1261,7 @@ def delete_notifications_cmd(
@wallet_cmd.group("vcs", short_help="Verifiable Credential related actions")
def vcs_cmd(): # pragma: no cover
def vcs_cmd() -> None: # pragma: no cover
pass

View File

@ -56,7 +56,7 @@ def transaction_description_from_type(tx: TransactionRecord) -> str:
def print_transaction(
tx: TransactionRecord,
verbose: bool,
name,
name: str,
address_prefix: str,
mojo_per_unit: int,
coin_record: Optional[Dict[str, Any]] = None,
@ -115,14 +115,14 @@ async def get_unit_name_for_wallet_id(
wallet_type: WalletType,
wallet_id: int,
wallet_client: WalletRpcClient,
):
) -> str:
if wallet_type in {
WalletType.STANDARD_WALLET,
WalletType.POOLING_WALLET,
WalletType.DATA_LAYER,
WalletType.VC,
}: # pragma: no cover
name = config["network_overrides"]["config"][config["selected_network"]]["address_prefix"].upper()
name: str = config["network_overrides"]["config"][config["selected_network"]]["address_prefix"].upper()
elif wallet_type == WalletType.CAT:
name = await wallet_client.get_cat_name(wallet_id=wallet_id)
else:
@ -244,7 +244,7 @@ async def get_transactions(
break
def check_unusual_transaction(amount: Decimal, fee: Decimal):
def check_unusual_transaction(amount: Decimal, fee: Decimal) -> bool:
return fee >= amount
@ -418,7 +418,7 @@ async def make_offer(
return
fee: int = int(d_fee * units["chia"])
if [] in [offers, requests]:
if len(offers) == 0 or len(requests) == 0:
print("Not creating offer: Must be offering and requesting at least one asset")
else:
offer_dict: Dict[Union[uint32, str], int] = {}
@ -569,13 +569,13 @@ async def make_offer(
print("Error creating offer")
def timestamp_to_time(timestamp):
def timestamp_to_time(timestamp: int) -> str:
return datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
async def print_offer_summary(
cat_name_resolver: CATNameResolver, sum_dict: Dict[str, int], has_fee: bool = False, network_xch="XCH"
):
cat_name_resolver: CATNameResolver, sum_dict: Dict[str, int], has_fee: bool = False, network_xch: str = "XCH"
) -> None:
for asset_id, amount in sum_dict.items():
description: str = ""
unit: int = units["chia"]
@ -608,7 +608,7 @@ async def print_offer_summary(
print(output)
async def print_trade_record(record, wallet_client: WalletRpcClient, summaries: bool = False) -> None:
async def print_trade_record(record: TradeRecord, wallet_client: WalletRpcClient, summaries: bool = False) -> None:
print()
print(f"Record with id: {record.trade_id}")
print("---------------")
@ -904,7 +904,7 @@ async def print_balances(
print(f"{indent}{'-Wallet ID:'.ljust(23)} {wallet_id}")
print(" ")
trusted_peers: Dict = config["wallet"].get("trusted_peers", {})
trusted_peers: dict[str, str] = config["wallet"].get("trusted_peers", {})
await print_connections(wallet_client, trusted_peers)

View File

@ -875,7 +875,7 @@ class WalletRpcClient(RpcClient):
await self.fetch("cancel_offer", {"trade_id": trade_id.hex(), "secure": secure, "fee": fee})
# NFT wallet
async def create_new_nft_wallet(self, did_id, name=None):
async def create_new_nft_wallet(self, did_id, name=None) -> dict[str, Any]:
request: Dict[str, Any] = {
"wallet_type": "nft_wallet",
"did_id": did_id,
@ -986,7 +986,7 @@ class WalletRpcClient(RpcClient):
response = await self.fetch("nft_count_nfts", request)
return response
async def list_nfts(self, wallet_id):
async def list_nfts(self, wallet_id) -> dict[str, Any]:
request: Dict[str, Any] = {"wallet_id": wallet_id, "num": 100_000}
response = await self.fetch("nft_get_nfts", request)
return response
@ -1009,7 +1009,7 @@ class WalletRpcClient(RpcClient):
response = await self.fetch("nft_set_nft_did", request)
return response
async def get_nft_wallet_did(self, wallet_id):
async def get_nft_wallet_did(self, wallet_id) -> dict[str, Optional[str]]:
request: Dict[str, Any] = {"wallet_id": wallet_id}
response = await self.fetch("nft_get_wallet_did", request)
return response

View File

@ -1,9 +1,5 @@
# File created by: python manage-mypy.py build-exclusions
chia.cmds.plots
chia.cmds.plotters
chia.cmds.start_funcs
chia.cmds.wallet
chia.cmds.wallet_funcs
chia.daemon.server
chia.introducer.introducer
chia.introducer.introducer_api