@@ -80,16 +80,16 @@ def my_completer(text: str, line: str, begidx: int, endidx:int, extra_param: str
80
80
81
81
82
82
class CompletionItem (str ):
83
- def __new__ (cls , o , desc = '' , * args , ** kwargs ):
83
+ def __new__ (cls , o , desc = '' , * args , ** kwargs ) -> str :
84
84
return str .__new__ (cls , o , * args , ** kwargs )
85
85
86
86
# noinspection PyMissingConstructor,PyUnusedLocal
87
- def __init__ (self , o , desc = '' , * args , ** kwargs ):
87
+ def __init__ (self , o , desc = '' , * args , ** kwargs ) -> None :
88
88
self .description = desc
89
89
90
90
91
91
class _RangeAction (object ):
92
- def __init__ (self , nargs : Union [int , str , Tuple [int , int ], None ]):
92
+ def __init__ (self , nargs : Union [int , str , Tuple [int , int ], None ]) -> None :
93
93
self .nargs_min = None
94
94
self .nargs_max = None
95
95
@@ -128,7 +128,7 @@ def __init__(self,
128
128
choices = None ,
129
129
required = False ,
130
130
help = None ,
131
- metavar = None ):
131
+ metavar = None ) -> None :
132
132
133
133
_RangeAction .__init__ (self , nargs )
134
134
@@ -157,7 +157,7 @@ def __init__(self,
157
157
choices = None ,
158
158
required = False ,
159
159
help = None ,
160
- metavar = None ):
160
+ metavar = None ) -> None :
161
161
162
162
_RangeAction .__init__ (self , nargs )
163
163
@@ -174,7 +174,7 @@ def __init__(self,
174
174
metavar = metavar )
175
175
176
176
177
- def register_custom_actions (parser : argparse .ArgumentParser ):
177
+ def register_custom_actions (parser : argparse .ArgumentParser ) -> None :
178
178
"""Register custom argument action types"""
179
179
parser .register ('action' , None , _StoreRangeAction )
180
180
parser .register ('action' , 'store' , _StoreRangeAction )
@@ -185,14 +185,14 @@ class AutoCompleter(object):
185
185
"""Automatically command line tab completion based on argparse parameters"""
186
186
187
187
class _ArgumentState (object ):
188
- def __init__ (self ):
188
+ def __init__ (self ) -> None :
189
189
self .min = None
190
190
self .max = None
191
191
self .count = 0
192
192
self .needed = False
193
193
self .variable = False
194
194
195
- def reset (self ):
195
+ def reset (self ) -> None :
196
196
"""reset tracking values"""
197
197
self .min = None
198
198
self .max = None
@@ -206,7 +206,7 @@ def __init__(self,
206
206
arg_choices : Dict [str , Union [List , Tuple , Callable ]] = None ,
207
207
subcmd_args_lookup : dict = None ,
208
208
tab_for_arg_help : bool = True ,
209
- cmd2_app = None ):
209
+ cmd2_app = None ) -> None :
210
210
"""
211
211
Create an AutoCompleter
212
212
@@ -439,7 +439,7 @@ def consume_positional_argument() -> None:
439
439
440
440
return completion_results
441
441
442
- def _format_completions (self , action , completions : List [Union [str , CompletionItem ]]):
442
+ def _format_completions (self , action , completions : List [Union [str , CompletionItem ]]) -> List [ str ] :
443
443
if completions and len (completions ) > 1 and isinstance (completions [0 ], CompletionItem ):
444
444
token_width = len (action .dest )
445
445
completions_with_desc = []
@@ -665,7 +665,7 @@ def basic_complete(text: str, line: str, begidx: int, endidx: int, match_against
665
665
class ACHelpFormatter (argparse .HelpFormatter ):
666
666
"""Custom help formatter to configure ordering of help text"""
667
667
668
- def _format_usage (self , usage , actions , groups , prefix ):
668
+ def _format_usage (self , usage , actions , groups , prefix ) -> str :
669
669
if prefix is None :
670
670
prefix = _ ('Usage: ' )
671
671
@@ -778,7 +778,7 @@ def get_lines(parts, indent, prefix=None):
778
778
# prefix with 'usage:'
779
779
return '%s%s\n \n ' % (prefix , usage )
780
780
781
- def _format_action_invocation (self , action ):
781
+ def _format_action_invocation (self , action ) -> str :
782
782
if not action .option_strings :
783
783
default = self ._get_default_metavar_for_positional (action )
784
784
metavar , = self ._metavar_formatter (action , default )(1 )
@@ -803,7 +803,7 @@ def _format_action_invocation(self, action):
803
803
return ', ' .join (action .option_strings ) + ' ' + args_string
804
804
# End cmd2 customization
805
805
806
- def _metavar_formatter (self , action , default_metavar ):
806
+ def _metavar_formatter (self , action , default_metavar ) -> Callable :
807
807
if action .metavar is not None :
808
808
result = action .metavar
809
809
elif action .choices is not None :
@@ -822,7 +822,7 @@ def format(tuple_size):
822
822
return (result , ) * tuple_size
823
823
return format
824
824
825
- def _format_args (self , action , default_metavar ):
825
+ def _format_args (self , action , default_metavar ) -> str :
826
826
get_metavar = self ._metavar_formatter (action , default_metavar )
827
827
# Begin cmd2 customization (less verbose)
828
828
if isinstance (action , _RangeAction ) and \
@@ -837,15 +837,15 @@ def _format_args(self, action, default_metavar):
837
837
result = super ()._format_args (action , default_metavar )
838
838
return result
839
839
840
- def _split_lines (self , text , width ):
840
+ def _split_lines (self , text : str , width ) -> List [ str ] :
841
841
return text .splitlines ()
842
842
843
843
844
844
# noinspection PyCompatibility
845
845
class ACArgumentParser (argparse .ArgumentParser ):
846
846
"""Custom argparse class to override error method to change default help text."""
847
847
848
- def __init__ (self , * args , ** kwargs ):
848
+ def __init__ (self , * args , ** kwargs ) -> None :
849
849
if 'formatter_class' not in kwargs :
850
850
kwargs ['formatter_class' ] = ACHelpFormatter
851
851
@@ -855,15 +855,15 @@ def __init__(self, *args, **kwargs):
855
855
self ._custom_error_message = ''
856
856
857
857
# Begin cmd2 customization
858
- def set_custom_message (self , custom_message = '' ):
858
+ def set_custom_message (self , custom_message : str = '' ) -> None :
859
859
"""
860
860
Allows an error message override to the error() function, useful when forcing a
861
861
re-parse of arguments with newly required parameters
862
862
"""
863
863
self ._custom_error_message = custom_message
864
864
# End cmd2 customization
865
865
866
- def error (self , message ) :
866
+ def error (self , message : str ) -> None :
867
867
"""Custom error override. Allows application to control the error being displayed by argparse"""
868
868
if len (self ._custom_error_message ) > 0 :
869
869
message = self ._custom_error_message
@@ -884,7 +884,7 @@ def error(self, message):
884
884
self .print_help ()
885
885
sys .exit (1 )
886
886
887
- def format_help (self ):
887
+ def format_help (self ) -> str :
888
888
"""Copy of format_help() from argparse.ArgumentParser with tweaks to separately display required parameters"""
889
889
formatter = self ._get_formatter ()
890
890
@@ -934,7 +934,7 @@ def format_help(self):
934
934
# determine help from format above
935
935
return formatter .format_help ()
936
936
937
- def _get_nargs_pattern (self , action ):
937
+ def _get_nargs_pattern (self , action ) -> str :
938
938
# Override _get_nargs_pattern behavior to use the nargs ranges provided by AutoCompleter
939
939
if isinstance (action , _RangeAction ) and \
940
940
action .nargs_min is not None and action .nargs_max is not None :
@@ -947,7 +947,7 @@ def _get_nargs_pattern(self, action):
947
947
return nargs_pattern
948
948
return super (ACArgumentParser , self )._get_nargs_pattern (action )
949
949
950
- def _match_argument (self , action , arg_strings_pattern ):
950
+ def _match_argument (self , action , arg_strings_pattern ) -> int :
951
951
# match the pattern for this action to the arg strings
952
952
nargs_pattern = self ._get_nargs_pattern (action )
953
953
match = _re .match (nargs_pattern , arg_strings_pattern )
@@ -963,7 +963,7 @@ def _match_argument(self, action, arg_strings_pattern):
963
963
964
964
# This is the official python implementation with a 5 year old patch applied
965
965
# See the comment below describing the patch
966
- def _parse_known_args (self , arg_strings , namespace ): # pragma: no cover
966
+ def _parse_known_args (self , arg_strings , namespace ) -> Tuple [ argparse . Namespace , List [ str ]] : # pragma: no cover
967
967
# replace arg strings that are file references
968
968
if self .fromfile_prefix_chars is not None :
969
969
arg_strings = self ._read_args_from_files (arg_strings )
0 commit comments