From 74aa5985919a23191201d9e44f986b022dfba83a Mon Sep 17 00:00:00 2001 From: bdhimes Date: Wed, 13 Aug 2025 21:47:40 +0200 Subject: [PATCH 01/12] Ensure hotkeys are into lists before any processing --- bittensor_cli/cli.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 6604c08b7..766086f60 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -3827,7 +3827,23 @@ def stake_remove( if amount and amount <= 0: print_error(f"You entered an incorrect unstake amount: {amount}") - raise typer.Exit() + return False + + if include_hotkeys: + include_hotkeys = parse_to_list( + include_hotkeys, + str, + "Hotkeys must be a comma-separated list of ss58s or names, e.g., `--include-hotkeys hk1,hk2`.", + is_ss58=False, + ) + + if exclude_hotkeys: + exclude_hotkeys = parse_to_list( + exclude_hotkeys, + str, + "Hotkeys must be a comma-separated list of ss58s or names, e.g., `--exclude-hotkeys hk3,hk4`.", + is_ss58=False, + ) if ( not wallet_hotkey From 97b2b7591c71b2f5baf20752c893c331eeffdb9c Mon Sep 17 00:00:00 2001 From: bdhimes Date: Wed, 13 Aug 2025 21:48:01 +0200 Subject: [PATCH 02/12] Correct type annotations --- bittensor_cli/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 766086f60..2d09335a0 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -12,7 +12,7 @@ import warnings from dataclasses import fields from pathlib import Path -from typing import Coroutine, Optional, Union +from typing import Coroutine, Optional, Union, Literal import numpy as np import rich @@ -1671,7 +1671,7 @@ def wallet_ask( wallet_name: Optional[str], wallet_path: Optional[str], wallet_hotkey: Optional[str], - ask_for: Optional[list[str]] = None, + ask_for: Optional[list[Union[str, Literal]]] = None, validate: WV = WV.WALLET, return_wallet_and_hotkey: bool = False, ) -> Union[Wallet, tuple[Wallet, str]]: From bfe20482ae4c2ccc1be7b00d9fb75405d8ce5316 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Wed, 13 Aug 2025 21:48:51 +0200 Subject: [PATCH 03/12] Raises to returns --- bittensor_cli/cli.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 2d09335a0..27762ed03 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -3798,11 +3798,11 @@ def stake_remove( "Interactive mode cannot be used with hotkey selection options like " "--include-hotkeys, --exclude-hotkeys, --all-hotkeys, or --hotkey." ) - raise typer.Exit() + return False if unstake_all and unstake_all_alpha: print_error("Cannot specify both unstake-all and unstake-all-alpha.") - raise typer.Exit() + return False if not interactive and not unstake_all and not unstake_all_alpha: netuid = get_optional_netuid(netuid, all_netuids) @@ -3811,19 +3811,19 @@ def stake_remove( "You have specified hotkeys to include and also the `--all-hotkeys` flag. The flag" " should only be used standalone (to use all hotkeys) or with `--exclude-hotkeys`." ) - raise typer.Exit() + return False if include_hotkeys and exclude_hotkeys: print_error( "You have specified both including and excluding hotkeys options. Select one or the other." ) - raise typer.Exit() + return False if unstake_all and amount: print_error( "Cannot specify both a specific amount and 'unstake-all'. Choose one or the other." ) - raise typer.Exit() + return False if amount and amount <= 0: print_error(f"You entered an incorrect unstake amount: {amount}") @@ -3891,12 +3891,12 @@ def stake_remove( if include_hotkeys: if len(include_hotkeys) > 1: print_error("Cannot unstake_all from multiple hotkeys at once.") - raise typer.Exit() + return False elif is_valid_ss58_address(include_hotkeys[0]): hotkey_ss58_address = include_hotkeys[0] else: print_error("Invalid hotkey ss58 address.") - raise typer.Exit() + return False elif all_hotkeys: wallet = self.wallet_ask( wallet_name, @@ -3981,6 +3981,7 @@ def stake_remove( "Hotkeys must be a comma-separated list of ss58s or names, e.g., `--include-hotkeys hk1,hk2`.", is_ss58=False, ) + return False if exclude_hotkeys: exclude_hotkeys = parse_to_list( @@ -3989,6 +3990,7 @@ def stake_remove( "Hotkeys must be a comma-separated list of ss58s or names, e.g., `--exclude-hotkeys hk3,hk4`.", is_ss58=False, ) + return False return self._run_command( remove_stake.unstake( From a698c01db1d8adc85a6e5e4a65cba186ab6e2066 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Wed, 13 Aug 2025 21:49:06 +0200 Subject: [PATCH 04/12] Formatting line length --- bittensor_cli/cli.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 27762ed03..c555161e1 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -3860,7 +3860,8 @@ def stake_remove( default=self.config.get("wallet_name") or defaults.wallet.name, ) hotkey_or_ss58 = Prompt.ask( - "Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake from [dim](or Press Enter to view existing staked hotkeys)[/dim]", + "Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake from [dim]" + "(or Press Enter to view existing staked hotkeys)[/dim]", ) if hotkey_or_ss58 == "": wallet = self.wallet_ask( @@ -3907,7 +3908,8 @@ def stake_remove( else: if not hotkey_ss58_address and not wallet_hotkey: hotkey_or_ss58 = Prompt.ask( - "Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake all from [dim](or enter 'all' to unstake from all hotkeys)[/dim]", + "Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake all from [dim]" + "(or enter 'all' to unstake from all hotkeys)[/dim]", default=self.config.get("wallet_hotkey") or defaults.wallet.hotkey, ) From 3921e84d0d0146de2ee1703f8672d74a12700830 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Wed, 13 Aug 2025 21:49:37 +0200 Subject: [PATCH 05/12] Error if using ambiguous args --- bittensor_cli/cli.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index c555161e1..f9faa2a0a 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -3975,22 +3975,21 @@ def stake_remove( ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) - - if include_hotkeys: - include_hotkeys = parse_to_list( - include_hotkeys, - str, - "Hotkeys must be a comma-separated list of ss58s or names, e.g., `--include-hotkeys hk1,hk2`.", - is_ss58=False, + if not amount and not prompt: + print_error( + f"Too ambiguous to use [{COLORS.G.ARG}]--no-prompt[/{COLORS.G.ARG}]. You need to specify an amount," + f"or use " + f"[{COLORS.G.ARG}]--unstake-all[/{COLORS.G.ARG}]/[{COLORS.G.ARG}]--unstake-all-alpha[/{COLORS.G.ARG}]." ) return False - if exclude_hotkeys: - exclude_hotkeys = parse_to_list( - exclude_hotkeys, - str, - "Hotkeys must be a comma-separated list of ss58s or names, e.g., `--exclude-hotkeys hk3,hk4`.", - is_ss58=False, + if not amount and json_output: + json_console.print_json( + data={ + "success": False, + "err_msg": "Too amibuous to use '--no-prompt' without specifying and amount or " + "'--unstake-all'/'--unstake-all-alpha'", + } ) return False From 4eb75af91c27d746ab2ed38a0b530d882685baf4 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Wed, 13 Aug 2025 21:54:59 +0200 Subject: [PATCH 06/12] Fix typing --- bittensor_cli/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index f9faa2a0a..8f6a204cb 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -1671,7 +1671,9 @@ def wallet_ask( wallet_name: Optional[str], wallet_path: Optional[str], wallet_hotkey: Optional[str], - ask_for: Optional[list[Union[str, Literal]]] = None, + ask_for: Optional[ + list[Union[str, Literal[WO.NAME, WO.PATH, WO.HOTKEY]]] + ] = None, validate: WV = WV.WALLET, return_wallet_and_hotkey: bool = False, ) -> Union[Wallet, tuple[Wallet, str]]: From ddd01c0f21ab94544e6be93d5d4cdba5e6e53b0d Mon Sep 17 00:00:00 2001 From: bdhimes Date: Wed, 13 Aug 2025 21:55:37 +0200 Subject: [PATCH 07/12] Fix typing --- bittensor_cli/cli.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 8f6a204cb..69784d02d 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -1671,9 +1671,7 @@ def wallet_ask( wallet_name: Optional[str], wallet_path: Optional[str], wallet_hotkey: Optional[str], - ask_for: Optional[ - list[Union[str, Literal[WO.NAME, WO.PATH, WO.HOTKEY]]] - ] = None, + ask_for: Optional[list[Literal[WO.NAME, WO.PATH, WO.HOTKEY]]] = None, validate: WV = WV.WALLET, return_wallet_and_hotkey: bool = False, ) -> Union[Wallet, tuple[Wallet, str]]: From 1a5f10f1a5bab519a2cd06fdf57beb3ab552238d Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 13 Aug 2025 16:27:44 -0400 Subject: [PATCH 08/12] fix typo and wording --- bittensor_cli/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 69784d02d..7665cd350 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -3987,7 +3987,7 @@ def stake_remove( json_console.print_json( data={ "success": False, - "err_msg": "Too amibuous to use '--no-prompt' without specifying and amount or " + "err_msg": "Just using '--no-prompt' is too ambiguous without specifying an amount or " "'--unstake-all'/'--unstake-all-alpha'", } ) From 563a75037a83a6be41207ffbb5ebd2b4042a0774 Mon Sep 17 00:00:00 2001 From: BD Himes <37844818+thewhaleking@users.noreply.github.com> Date: Wed, 13 Aug 2025 22:28:23 +0200 Subject: [PATCH 09/12] Update bittensor_cli/cli.py Co-authored-by: Cameron Fairchild --- bittensor_cli/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 7665cd350..6072c378f 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -3977,7 +3977,7 @@ def stake_remove( ) if not amount and not prompt: print_error( - f"Too ambiguous to use [{COLORS.G.ARG}]--no-prompt[/{COLORS.G.ARG}]. You need to specify an amount," + f"Just using [{COLORS.G.ARG}]--no-prompt[/{COLORS.G.ARG}] is too ambiguous. You need to specify an amount," f"or use " f"[{COLORS.G.ARG}]--unstake-all[/{COLORS.G.ARG}]/[{COLORS.G.ARG}]--unstake-all-alpha[/{COLORS.G.ARG}]." ) From 7da9dd5fe1b5a2ec2f518d921965a50c79ce189a Mon Sep 17 00:00:00 2001 From: bdhimes Date: Wed, 13 Aug 2025 22:36:44 +0200 Subject: [PATCH 10/12] Update wording --- bittensor_cli/cli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 6072c378f..458cf1d4b 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -3977,8 +3977,8 @@ def stake_remove( ) if not amount and not prompt: print_error( - f"Just using [{COLORS.G.ARG}]--no-prompt[/{COLORS.G.ARG}] is too ambiguous. You need to specify an amount," - f"or use " + f"Using [{COLORS.G.ARG}]--no-prompt[/{COLORS.G.ARG}] without an amount/all is too ambiguous. " + f"You need to specify an [{COLORS.G.ARG}]--amount[/{COLORS.G.ARG}] or use " f"[{COLORS.G.ARG}]--unstake-all[/{COLORS.G.ARG}]/[{COLORS.G.ARG}]--unstake-all-alpha[/{COLORS.G.ARG}]." ) return False @@ -3987,8 +3987,8 @@ def stake_remove( json_console.print_json( data={ "success": False, - "err_msg": "Just using '--no-prompt' is too ambiguous without specifying an amount or " - "'--unstake-all'/'--unstake-all-alpha'", + "err_msg": "Using '--json-output' without an amount/all is too ambiguous. You need to specify an " + "'--amount' or use '--unstake-all'/'--unstake-all-alpha'", } ) return False From 2511eb24eef275d53380836f762be1df2db99cc3 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Wed, 13 Aug 2025 22:37:35 +0200 Subject: [PATCH 11/12] Update wording --- bittensor_cli/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 458cf1d4b..fbad86ba6 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -3977,7 +3977,7 @@ def stake_remove( ) if not amount and not prompt: print_error( - f"Using [{COLORS.G.ARG}]--no-prompt[/{COLORS.G.ARG}] without an amount/all is too ambiguous. " + f"Using [{COLORS.G.ARG}]--no-prompt[/{COLORS.G.ARG}] without an amount/'all' is too ambiguous. " f"You need to specify an [{COLORS.G.ARG}]--amount[/{COLORS.G.ARG}] or use " f"[{COLORS.G.ARG}]--unstake-all[/{COLORS.G.ARG}]/[{COLORS.G.ARG}]--unstake-all-alpha[/{COLORS.G.ARG}]." ) @@ -3987,7 +3987,7 @@ def stake_remove( json_console.print_json( data={ "success": False, - "err_msg": "Using '--json-output' without an amount/all is too ambiguous. You need to specify an " + "err_msg": "Using '--json-output' without an amount/'all' is too ambiguous. You need to specify an " "'--amount' or use '--unstake-all'/'--unstake-all-alpha'", } ) From e96a5c8f7951f7f496f1024208b86e2aac572bbe Mon Sep 17 00:00:00 2001 From: bdhimes Date: Thu, 14 Aug 2025 16:15:07 +0200 Subject: [PATCH 12/12] Update text --- bittensor_cli/cli.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index fbad86ba6..67fe1ef59 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -3977,9 +3977,9 @@ def stake_remove( ) if not amount and not prompt: print_error( - f"Using [{COLORS.G.ARG}]--no-prompt[/{COLORS.G.ARG}] without an amount/'all' is too ambiguous. " - f"You need to specify an [{COLORS.G.ARG}]--amount[/{COLORS.G.ARG}] or use " - f"[{COLORS.G.ARG}]--unstake-all[/{COLORS.G.ARG}]/[{COLORS.G.ARG}]--unstake-all-alpha[/{COLORS.G.ARG}]." + f"Ambiguous request! Specify [{COLORS.G.ARG}]--amount[/{COLORS.G.ARG}], " + f"[{COLORS.G.ARG}]--all[/{COLORS.G.ARG}], " + f"or [{COLORS.G.ARG}]--all-alpha[/{COLORS.G.ARG}] to use [{COLORS.G.ARG}]--no-prompt[/{COLORS.G.ARG}]" ) return False @@ -3987,8 +3987,8 @@ def stake_remove( json_console.print_json( data={ "success": False, - "err_msg": "Using '--json-output' without an amount/'all' is too ambiguous. You need to specify an " - "'--amount' or use '--unstake-all'/'--unstake-all-alpha'", + "err_msg": "Ambiguous request! Specify '--amount', '--all', " + "or '--all-alpha' to use '--json-output'", } ) return False