@@ -250,15 +250,11 @@ def my_completer(self, text, line, begidx, endidx, arg_tokens)
250
250
TYPE_CHECKING ,
251
251
Any ,
252
252
Callable ,
253
- Dict ,
254
253
Iterable ,
255
- List ,
256
254
NoReturn ,
257
255
Optional ,
258
256
Protocol ,
259
257
Sequence ,
260
- Set ,
261
- Tuple ,
262
258
Type ,
263
259
Union ,
264
260
cast ,
@@ -350,7 +346,7 @@ class ChoicesProviderFuncBase(Protocol):
350
346
Function that returns a list of choices in support of tab completion
351
347
"""
352
348
353
- def __call__ (self ) -> List [str ]: ... # pragma: no cover
349
+ def __call__ (self ) -> list [str ]: ... # pragma: no cover
354
350
355
351
356
352
@runtime_checkable
@@ -359,7 +355,7 @@ class ChoicesProviderFuncWithTokens(Protocol):
359
355
Function that returns a list of choices in support of tab completion and accepts a dictionary of prior arguments.
360
356
"""
361
357
362
- def __call__ (self , * , arg_tokens : Dict [str , List [str ]] = {}) -> List [str ]: ... # pragma: no cover
358
+ def __call__ (self , * , arg_tokens : dict [str , list [str ]] = {}) -> list [str ]: ... # pragma: no cover
363
359
364
360
365
361
ChoicesProviderFunc = Union [ChoicesProviderFuncBase , ChoicesProviderFuncWithTokens ]
@@ -377,7 +373,7 @@ def __call__(
377
373
line : str ,
378
374
begidx : int ,
379
375
endidx : int ,
380
- ) -> List [str ]: ... # pragma: no cover
376
+ ) -> list [str ]: ... # pragma: no cover
381
377
382
378
383
379
@runtime_checkable
@@ -394,8 +390,8 @@ def __call__(
394
390
begidx : int ,
395
391
endidx : int ,
396
392
* ,
397
- arg_tokens : Dict [str , List [str ]] = {},
398
- ) -> List [str ]: ... # pragma: no cover
393
+ arg_tokens : dict [str , list [str ]] = {},
394
+ ) -> list [str ]: ... # pragma: no cover
399
395
400
396
401
397
CompleterFunc = Union [CompleterFuncBase , CompleterFuncWithTokens ]
@@ -598,7 +594,7 @@ def _action_set_descriptive_header(self: argparse.Action, descriptive_header: Op
598
594
############################################################################################################
599
595
# Patch argparse.Action with accessors for nargs_range attribute
600
596
############################################################################################################
601
- def _action_get_nargs_range (self : argparse .Action ) -> Optional [Tuple [int , Union [int , float ]]]:
597
+ def _action_get_nargs_range (self : argparse .Action ) -> Optional [tuple [int , Union [int , float ]]]:
602
598
"""
603
599
Get the nargs_range attribute of an argparse Action.
604
600
@@ -609,13 +605,13 @@ def _action_get_nargs_range(self: argparse.Action) -> Optional[Tuple[int, Union[
609
605
:param self: argparse Action being queried
610
606
:return: The value of nargs_range or None if attribute does not exist
611
607
"""
612
- return cast (Optional [Tuple [int , Union [int , float ]]], getattr (self , ATTR_NARGS_RANGE , None ))
608
+ return cast (Optional [tuple [int , Union [int , float ]]], getattr (self , ATTR_NARGS_RANGE , None ))
613
609
614
610
615
611
setattr (argparse .Action , 'get_nargs_range' , _action_get_nargs_range )
616
612
617
613
618
- def _action_set_nargs_range (self : argparse .Action , nargs_range : Optional [Tuple [int , Union [int , float ]]]) -> None :
614
+ def _action_set_nargs_range (self : argparse .Action , nargs_range : Optional [tuple [int , Union [int , float ]]]) -> None :
619
615
"""
620
616
Set the nargs_range attribute of an argparse Action.
621
617
@@ -673,7 +669,7 @@ def _action_set_suppress_tab_hint(self: argparse.Action, suppress_tab_hint: bool
673
669
# Allow developers to add custom action attributes
674
670
############################################################################################################
675
671
676
- CUSTOM_ACTION_ATTRIBS : Set [str ] = set ()
672
+ CUSTOM_ACTION_ATTRIBS : set [str ] = set ()
677
673
_CUSTOM_ATTRIB_PFX = '_attr_'
678
674
679
675
@@ -746,7 +742,7 @@ def _action_set_custom_parameter(self: argparse.Action, value: Any) -> None:
746
742
def _add_argument_wrapper (
747
743
self : argparse ._ActionsContainer ,
748
744
* args : Any ,
749
- nargs : Union [int , str , Tuple [int ], Tuple [int , int ], Tuple [int , float ], None ] = None ,
745
+ nargs : Union [int , str , tuple [int ], tuple [int , int ], tuple [int , float ], None ] = None ,
750
746
choices_provider : Optional [ChoicesProviderFunc ] = None ,
751
747
completer : Optional [CompleterFunc ] = None ,
752
748
suppress_tab_hint : bool = False ,
@@ -797,7 +793,7 @@ def _add_argument_wrapper(
797
793
nargs_range = None
798
794
799
795
if nargs is not None :
800
- nargs_adjusted : Union [int , str , Tuple [int ], Tuple [int , int ], Tuple [int , float ], None ]
796
+ nargs_adjusted : Union [int , str , tuple [int ], tuple [int , int ], tuple [int , float ], None ]
801
797
# Check if nargs was given as a range
802
798
if isinstance (nargs , tuple ):
803
799
# Handle 1-item tuple by setting max to INFINITY
@@ -847,7 +843,7 @@ def _add_argument_wrapper(
847
843
kwargs ['nargs' ] = nargs_adjusted
848
844
849
845
# Extract registered custom keyword arguments
850
- custom_attribs : Dict [str , Any ] = {}
846
+ custom_attribs : dict [str , Any ] = {}
851
847
for keyword , value in kwargs .items ():
852
848
if keyword in CUSTOM_ACTION_ATTRIBS :
853
849
custom_attribs [keyword ] = value
@@ -1124,9 +1120,9 @@ def _format_usage(
1124
1120
# End cmd2 customization
1125
1121
1126
1122
# helper for wrapping lines
1127
- def get_lines (parts : List [str ], indent : str , prefix : Optional [str ] = None ) -> List [str ]:
1128
- lines : List [str ] = []
1129
- line : List [str ] = []
1123
+ def get_lines (parts : list [str ], indent : str , prefix : Optional [str ] = None ) -> list [str ]:
1124
+ lines : list [str ] = []
1125
+ line : list [str ] = []
1130
1126
if prefix is not None :
1131
1127
line_len = len (prefix ) - 1
1132
1128
else :
@@ -1188,7 +1184,7 @@ def _format_action_invocation(self, action: argparse.Action) -> str:
1188
1184
return metavar
1189
1185
1190
1186
else :
1191
- parts : List [str ] = []
1187
+ parts : list [str ] = []
1192
1188
1193
1189
# if the Optional doesn't take a value, format is:
1194
1190
# -s, --long
@@ -1209,8 +1205,8 @@ def _format_action_invocation(self, action: argparse.Action) -> str:
1209
1205
def _determine_metavar (
1210
1206
self ,
1211
1207
action : argparse .Action ,
1212
- default_metavar : Union [str , Tuple [str , ...]],
1213
- ) -> Union [str , Tuple [str , ...]]:
1208
+ default_metavar : Union [str , tuple [str , ...]],
1209
+ ) -> Union [str , tuple [str , ...]]:
1214
1210
"""Custom method to determine what to use as the metavar value of an action"""
1215
1211
if action .metavar is not None :
1216
1212
result = action .metavar
@@ -1226,19 +1222,19 @@ def _determine_metavar(
1226
1222
def _metavar_formatter (
1227
1223
self ,
1228
1224
action : argparse .Action ,
1229
- default_metavar : Union [str , Tuple [str , ...]],
1230
- ) -> Callable [[int ], Tuple [str , ...]]:
1225
+ default_metavar : Union [str , tuple [str , ...]],
1226
+ ) -> Callable [[int ], tuple [str , ...]]:
1231
1227
metavar = self ._determine_metavar (action , default_metavar )
1232
1228
1233
- def format (tuple_size : int ) -> Tuple [str , ...]:
1229
+ def format (tuple_size : int ) -> tuple [str , ...]:
1234
1230
if isinstance (metavar , tuple ):
1235
1231
return metavar
1236
1232
else :
1237
1233
return (metavar ,) * tuple_size
1238
1234
1239
1235
return format
1240
1236
1241
- def _format_args (self , action : argparse .Action , default_metavar : Union [str , Tuple [str , ...]]) -> str :
1237
+ def _format_args (self , action : argparse .Action , default_metavar : Union [str , tuple [str , ...]]) -> str :
1242
1238
"""Customized to handle ranged nargs and make other output less verbose"""
1243
1239
metavar = self ._determine_metavar (action , default_metavar )
1244
1240
metavar_formatter = self ._metavar_formatter (action , default_metavar )
0 commit comments