1212from  typing  import  (
1313    IO ,
1414    TYPE_CHECKING ,
15-     Optional ,
16-     Union ,
1715    cast ,
1816)
1917
@@ -105,8 +103,8 @@ class _ArgumentState:
105103
106104    def  __init__ (self , arg_action : argparse .Action ) ->  None :
107105        self .action  =  arg_action 
108-         self .min : Union [ int ,  str ] 
109-         self .max : Union [ float ,  int ,  str ] 
106+         self .min : int   |   str 
107+         self .max : float   |   int   |   str 
110108        self .count  =  0 
111109        self .is_remainder  =  self .action .nargs  ==  argparse .REMAINDER 
112110
@@ -141,7 +139,7 @@ def __init__(self, flag_arg_state: _ArgumentState) -> None:
141139        :param flag_arg_state: information about the unfinished flag action. 
142140        """ 
143141        arg  =  f'{ argparse ._get_action_name (flag_arg_state .action )}  ' 
144-         err  =  f'{ generate_range_error (cast (int , flag_arg_state .min ), cast (Union [ int ,  float ] , flag_arg_state .max ))}  ' 
142+         err  =  f'{ generate_range_error (cast (int , flag_arg_state .min ), cast (int   |   float , flag_arg_state .max ))}  ' 
145143        error  =  f"Error: argument { arg }  : { err }   ({ flag_arg_state .count }   entered)" 
146144        super ().__init__ (error )
147145
@@ -163,7 +161,7 @@ class ArgparseCompleter:
163161    """Automatic command line tab completion based on argparse parameters.""" 
164162
165163    def  __init__ (
166-         self , parser : argparse .ArgumentParser , cmd2_app : 'Cmd' , * , parent_tokens : Optional [ dict [str , list [str ]]]  =  None 
164+         self , parser : argparse .ArgumentParser , cmd2_app : 'Cmd' , * , parent_tokens : dict [str , list [str ]]  |   None  =  None 
167165    ) ->  None :
168166        """Create an ArgparseCompleter. 
169167
@@ -203,7 +201,7 @@ def __init__(
203201                    self ._subcommand_action  =  action 
204202
205203    def  complete (
206-         self , text : str , line : str , begidx : int , endidx : int , tokens : list [str ], * , cmd_set : Optional [ CommandSet ]  =  None 
204+         self , text : str , line : str , begidx : int , endidx : int , tokens : list [str ], * , cmd_set : CommandSet   |   None  =  None 
207205    ) ->  list [str ]:
208206        """Complete text using argparse metadata. 
209207
@@ -228,10 +226,10 @@ def complete(
228226        skip_remaining_flags  =  False 
229227
230228        # _ArgumentState of the current positional 
231-         pos_arg_state : Optional [ _ArgumentState ]  =  None 
229+         pos_arg_state : _ArgumentState   |   None  =  None 
232230
233231        # _ArgumentState of the current flag 
234-         flag_arg_state : Optional [ _ArgumentState ]  =  None 
232+         flag_arg_state : _ArgumentState   |   None  =  None 
235233
236234        # Non-reusable flags that we've parsed 
237235        matched_flags : list [str ] =  []
@@ -523,7 +521,7 @@ def _complete_flags(self, text: str, line: str, begidx: int, endidx: int, matche
523521
524522        return  matches 
525523
526-     def  _format_completions (self , arg_state : _ArgumentState , completions : Union [ list [str ],  list [CompletionItem ] ]) ->  list [str ]:
524+     def  _format_completions (self , arg_state : _ArgumentState , completions : list [str ]  |   list [CompletionItem ]) ->  list [str ]:
527525        """Format CompletionItems into hint table.""" 
528526        # Nothing to do if we don't have at least 2 completions which are all CompletionItems 
529527        if  len (completions ) <  2  or  not  all (isinstance (c , CompletionItem ) for  c  in  completions ):
@@ -625,7 +623,7 @@ def complete_subcommand_help(self, text: str, line: str, begidx: int, endidx: in
625623                break 
626624        return  []
627625
628-     def  print_help (self , tokens : list [str ], file : Optional [ IO [str ]]  =  None ) ->  None :
626+     def  print_help (self , tokens : list [str ], file : IO [str ]  |   None  =  None ) ->  None :
629627        """Supports cmd2's help command in the printing of help text. 
630628
631629        :param tokens: arguments passed to help command 
@@ -636,7 +634,7 @@ def print_help(self, tokens: list[str], file: Optional[IO[str]] = None) -> None:
636634        # If so, we will let the subcommand's parser handle the rest of the tokens via another ArgparseCompleter. 
637635        if  tokens  and  self ._subcommand_action  is  not   None :
638636            parser  =  cast (
639-                 Optional [ argparse .ArgumentParser ] ,
637+                 argparse .ArgumentParser   |   None ,
640638                self ._subcommand_action .choices .get (tokens [0 ]),
641639            )
642640
@@ -657,15 +655,15 @@ def _complete_arg(
657655        arg_state : _ArgumentState ,
658656        consumed_arg_values : dict [str , list [str ]],
659657        * ,
660-         cmd_set : Optional [ CommandSet ]  =  None ,
658+         cmd_set : CommandSet   |   None  =  None ,
661659    ) ->  list [str ]:
662660        """Tab completion routine for an argparse argument. 
663661
664662        :return: list of completions 
665663        :raises CompletionError: if the completer or choices function this calls raises one. 
666664        """ 
667665        # Check if the arg provides choices to the user 
668-         arg_choices : Union [ list [str ],  ChoicesCallable ] 
666+         arg_choices : list [str ]  |   ChoicesCallable 
669667        if  arg_state .action .choices  is  not   None :
670668            arg_choices  =  list (arg_state .action .choices )
671669            if  not  arg_choices :
0 commit comments