@@ -262,10 +262,10 @@ def build_range_error(range_min: int, range_max: float) -> str:
262262 err_msg = "expected "
263263
264264 if range_max == constants .INFINITY :
265- plural = '' if range_min == 1 else 's'
265+ plural = "" if range_min == 1 else "s"
266266 err_msg += f"at least { range_min } "
267267 else :
268- plural = '' if range_max == 1 else 's'
268+ plural = "" if range_max == 1 else "s"
269269 if range_min == range_max :
270270 err_msg += f"{ range_min } "
271271 else :
@@ -309,8 +309,8 @@ def register_argparse_argument_parameter(
309309 raise KeyError (f"'{ param_name } ' conflicts with an existing attribute on argparse.Action" )
310310
311311 # Check if accessors already exist (e.g., from manual patching or previous registration)
312- getter_name = f' get_{ param_name } '
313- setter_name = f' set_{ param_name } '
312+ getter_name = f" get_{ param_name } "
313+ setter_name = f" set_{ param_name } "
314314 if hasattr (argparse .Action , getter_name ) or hasattr (argparse .Action , setter_name ):
315315 raise KeyError (f"Accessor methods for '{ param_name } ' already exist on argparse.Action" )
316316
@@ -355,11 +355,11 @@ def _validate_completion_callable(self: argparse.Action, value: Any) -> Any:
355355
356356# Add new attributes to argparse.Action.
357357# See _ActionsContainer_add_argument() for details on these attributes.
358- register_argparse_argument_parameter (' choices_provider' , validator = _validate_completion_callable )
359- register_argparse_argument_parameter (' completer' , validator = _validate_completion_callable )
360- register_argparse_argument_parameter (' table_columns' )
361- register_argparse_argument_parameter (' nargs_range' )
362- register_argparse_argument_parameter (' suppress_tab_hint' )
358+ register_argparse_argument_parameter (" choices_provider" , validator = _validate_completion_callable )
359+ register_argparse_argument_parameter (" completer" , validator = _validate_completion_callable )
360+ register_argparse_argument_parameter (" table_columns" )
361+ register_argparse_argument_parameter (" nargs_range" )
362+ register_argparse_argument_parameter (" suppress_tab_hint" )
363363
364364
365365############################################################################################################
@@ -431,11 +431,11 @@ def _ActionsContainer_add_argument( # noqa: N802
431431 or not isinstance (nargs [0 ], int )
432432 or not (isinstance (nargs [1 ], int ) or nargs [1 ] == constants .INFINITY )
433433 ):
434- raise ValueError (' Ranged values for nargs must be a tuple of 1 or 2 integers' )
434+ raise ValueError (" Ranged values for nargs must be a tuple of 1 or 2 integers" )
435435 if nargs [0 ] >= nargs [1 ]:
436- raise ValueError (' Invalid nargs range. The first value must be less than the second' )
436+ raise ValueError (" Invalid nargs range. The first value must be less than the second" )
437437 if nargs [0 ] < 0 :
438- raise ValueError (' Negative numbers are invalid for nargs range' )
438+ raise ValueError (" Negative numbers are invalid for nargs range" )
439439
440440 # Save the nargs tuple as our range setting
441441 nargs_range = nargs
@@ -465,7 +465,7 @@ def _ActionsContainer_add_argument( # noqa: N802
465465 nargs_adjusted = nargs
466466
467467 # Add the argparse-recognized version of nargs to kwargs
468- kwargs [' nargs' ] = nargs_adjusted
468+ kwargs [" nargs" ] = nargs_adjusted
469469
470470 # Extract registered custom keyword arguments
471471 custom_attribs = {keyword : value for keyword , value in kwargs .items () if keyword in _CUSTOM_ACTION_ATTRIBS }
@@ -484,7 +484,7 @@ def _ActionsContainer_add_argument( # noqa: N802
484484
485485 # Set other registered custom attributes
486486 for keyword , value in custom_attribs .items ():
487- attr_setter = getattr (new_arg , f' set_{ keyword } ' , None )
487+ attr_setter = getattr (new_arg , f" set_{ keyword } " , None )
488488 if attr_setter is not None :
489489 attr_setter (value )
490490
@@ -506,17 +506,17 @@ def __init__(
506506 epilog : RenderableType | None = None ,
507507 parents : Sequence [argparse .ArgumentParser ] = (),
508508 formatter_class : type [Cmd2HelpFormatter ] = Cmd2HelpFormatter ,
509- prefix_chars : str = '-' ,
509+ prefix_chars : str = "-" ,
510510 fromfile_prefix_chars : str | None = None ,
511511 argument_default : str | None = None ,
512- conflict_handler : str = ' error' ,
512+ conflict_handler : str = " error" ,
513513 add_help : bool = True ,
514514 allow_abbrev : bool = True ,
515515 exit_on_error : bool = True ,
516516 suggest_on_error : bool = False ,
517517 color : bool = False ,
518518 * ,
519- ap_completer_type : type [' ArgparseCompleter' ] | None = None ,
519+ ap_completer_type : type [" ArgparseCompleter" ] | None = None ,
520520 ) -> None :
521521 """Initialize the Cmd2ArgumentParser instance.
522522
@@ -651,7 +651,7 @@ def update_prog(self, prog: str) -> None:
651651 subcmd_parser .update_prog (subcmd_prog )
652652 updated_parsers .add (subcmd_parser )
653653
654- def _find_parser (self , subcommand_path : Iterable [str ]) -> ' Cmd2ArgumentParser' :
654+ def _find_parser (self , subcommand_path : Iterable [str ]) -> " Cmd2ArgumentParser" :
655655 """Find a parser in the hierarchy based on a sequence of subcommand names.
656656
657657 :param subcommand_path: sequence of subcommand names leading to the target parser
@@ -670,7 +670,7 @@ def attach_subcommand(
670670 self ,
671671 subcommand_path : Iterable [str ],
672672 subcommand : str ,
673- subcommand_parser : ' Cmd2ArgumentParser' ,
673+ subcommand_parser : " Cmd2ArgumentParser" ,
674674 ** add_parser_kwargs : Any ,
675675 ) -> None :
676676 """Attach a parser as a subcommand to a command at the specified path.
@@ -719,7 +719,7 @@ def attach_subcommand(
719719 for alias in add_parser_kwargs .get ("aliases" , ()):
720720 subparsers_action ._name_parser_map [alias ] = subcommand_parser
721721
722- def detach_subcommand (self , subcommand_path : Iterable [str ], subcommand : str ) -> ' Cmd2ArgumentParser' :
722+ def detach_subcommand (self , subcommand_path : Iterable [str ], subcommand : str ) -> " Cmd2ArgumentParser" :
723723 """Detach a subcommand from a command at the specified path.
724724
725725 :param subcommand_path: sequence of subcommand names leading to the parser hosting the
@@ -753,13 +753,13 @@ def detach_subcommand(self, subcommand_path: Iterable[str], subcommand: str) ->
753753
754754 def error (self , message : str ) -> NoReturn :
755755 """Override that applies custom formatting to the error message."""
756- lines = message .split (' \n ' )
757- formatted_message = ''
756+ lines = message .split (" \n " )
757+ formatted_message = ""
758758 for linum , line in enumerate (lines ):
759759 if linum == 0 :
760- formatted_message = ' Error: ' + line
760+ formatted_message = " Error: " + line
761761 else :
762- formatted_message += ' \n ' + line
762+ formatted_message += " \n " + line
763763
764764 self .print_usage (sys .stderr )
765765
@@ -769,27 +769,27 @@ def error(self, message: str) -> NoReturn:
769769 console .print (formatted_message , style = Cmd2Style .ERROR )
770770 formatted_message = f"{ capture .get ()} "
771771
772- self .exit (2 , f' { formatted_message } \n ' )
772+ self .exit (2 , f" { formatted_message } \n " )
773773
774774 def _get_formatter (self , ** kwargs : Any ) -> Cmd2HelpFormatter :
775775 """Override with customizations for Cmd2HelpFormatter."""
776776 return cast (Cmd2HelpFormatter , super ()._get_formatter (** kwargs ))
777777
778778 def format_help (self ) -> str :
779779 """Override to add a newline."""
780- return super ().format_help () + ' \n '
780+ return super ().format_help () + " \n "
781781
782782 def _get_nargs_pattern (self , action : argparse .Action ) -> str :
783783 """Override to support nargs ranges."""
784784 nargs_range = action .get_nargs_range () # type: ignore[attr-defined]
785785 if nargs_range :
786- range_max = '' if nargs_range [1 ] == constants .INFINITY else nargs_range [1 ]
787- nargs_pattern = f' (-*A{{{ nargs_range [0 ]} ,{ range_max } }}-*)'
786+ range_max = "" if nargs_range [1 ] == constants .INFINITY else nargs_range [1 ]
787+ nargs_pattern = f" (-*A{{{ nargs_range [0 ]} ,{ range_max } }}-*)"
788788
789789 # if this is an optional action, -- is not allowed
790790 if action .option_strings :
791- nargs_pattern = nargs_pattern .replace ('-*' , '' )
792- nargs_pattern = nargs_pattern .replace ('-' , '' )
791+ nargs_pattern = nargs_pattern .replace ("-*" , "" )
792+ nargs_pattern = nargs_pattern .replace ("-" , "" )
793793 return nargs_pattern
794794
795795 return super ()._get_nargs_pattern (action )
@@ -823,8 +823,8 @@ def _check_value(self, action: argparse.Action, value: Any) -> None:
823823 if action .choices is not None and value not in action .choices :
824824 # If any choice is a CompletionItem, then display its value property.
825825 choices = [c .value if isinstance (c , CompletionItem ) else c for c in action .choices ]
826- args = {' value' : value , ' choices' : ', ' .join (map (repr , choices ))}
827- msg = _ (' invalid choice: %(value)r (choose from %(choices)s)' )
826+ args = {" value" : value , " choices" : ", " .join (map (repr , choices ))}
827+ msg = _ (" invalid choice: %(value)r (choose from %(choices)s)" )
828828 raise ArgumentError (action , msg % args )
829829
830830
0 commit comments