1- # type: ignore
1+ from __future__ import annotations
22
33import sys
44
1010class ConfirmBoolParamType (click .ParamType ):
1111 name = "confirmation"
1212
13- def convert (self , value , param , ctx ) :
13+ def convert (self , value : bool | str , param : click . Parameter | None , ctx : click . Context | None ) -> bool :
1414 if isinstance (value , bool ):
1515 return bool (value )
1616 value = value .lower ()
1717 if value in ("yes" , "y" ):
1818 return True
19- elif value in ("no" , "n" ):
19+ if value in ("no" , "n" ):
2020 return False
2121 self .fail ("%s is not a valid boolean" % value , param , ctx )
2222
@@ -27,7 +27,7 @@ def __repr__(self):
2727BOOLEAN_TYPE = ConfirmBoolParamType ()
2828
2929
30- def confirm_destructive_query (queries ) :
30+ def confirm_destructive_query (queries : str ) -> bool | None :
3131 """Check if the query is destructive and prompts the user to confirm.
3232
3333 Returns:
@@ -39,17 +39,19 @@ def confirm_destructive_query(queries):
3939 prompt_text = "You're about to run a destructive command.\n Do you want to proceed? (y/n)"
4040 if is_destructive (queries ) and sys .stdin .isatty ():
4141 return prompt (prompt_text , type = BOOLEAN_TYPE )
42+ else :
43+ return None
4244
4345
44- def confirm (* args , ** kwargs ):
46+ def confirm (* args , ** kwargs ) -> bool :
4547 """Prompt for confirmation (yes/no) and handle any abort exceptions."""
4648 try :
4749 return click .confirm (* args , ** kwargs )
4850 except click .Abort :
4951 return False
5052
5153
52- def prompt (* args , ** kwargs ):
54+ def prompt (* args , ** kwargs ) -> bool :
5355 """Prompt the user for input and handle any abort exceptions."""
5456 try :
5557 return click .prompt (* args , ** kwargs )
0 commit comments