4545 Callable ,
4646 Iterable ,
4747 Mapping ,
48+ MutableSequence ,
49+ Sequence ,
4850)
4951from types import FrameType
5052from typing import (
@@ -299,14 +301,14 @@ def __init__(
299301 include_ipy : bool = False ,
300302 include_py : bool = False ,
301303 intro : RenderableType = '' ,
302- multiline_commands : list [str ] | None = None ,
304+ multiline_commands : Iterable [str ] | None = None ,
303305 persistent_history_file : str = '' ,
304306 persistent_history_length : int = 1000 ,
305- shortcuts : dict [str , str ] | None = None ,
307+ shortcuts : Mapping [str , str ] | None = None ,
306308 silence_startup_script : bool = False ,
307309 startup_script : str = '' ,
308310 suggest_similar_command : bool = False ,
309- terminators : list [str ] | None = None ,
311+ terminators : Iterable [str ] | None = None ,
310312 ) -> None :
311313 """Easy but powerful framework for writing line-oriented command interpreters, extends Python's cmd package.
312314
@@ -337,24 +339,24 @@ def __init__(
337339 :param include_ipy: should the "ipy" command be included for an embedded IPython shell
338340 :param include_py: should the "py" command be included for an embedded Python shell
339341 :param intro: introduction to display at startup
340- :param multiline_commands: list of commands allowed to accept multi-line input
342+ :param multiline_commands: Iterable of commands allowed to accept multi-line input
341343 :param persistent_history_file: file path to load a persistent cmd2 command history from
342344 :param persistent_history_length: max number of history items to write
343345 to the persistent history file
344- :param shortcuts: dictionary containing shortcuts for commands. If not supplied,
346+ :param shortcuts: Mapping containing shortcuts for commands. If not supplied,
345347 then defaults to constants.DEFAULT_SHORTCUTS. If you do not want
346- any shortcuts, pass an empty dictionary.
348+ any shortcuts, pass None and an empty dictionary will be created .
347349 :param silence_startup_script: if ``True``, then the startup script's output will be
348350 suppressed. Anything written to stderr will still display.
349351 :param startup_script: file path to a script to execute at startup
350352 :param suggest_similar_command: if ``True``, then when a command is not found,
351353 [cmd2.Cmd][] will look for similar commands and suggest them.
352- :param terminators: list of characters that terminate a command. These are mainly
354+ :param terminators: Iterable of characters that terminate a command. These are mainly
353355 intended for terminating multiline commands, but will also
354356 terminate single-line commands. If not supplied, the default
355357 is a semicolon. If your app only contains single-line commands
356358 and you want terminators to be treated as literals by the parser,
357- then set this to an empty list .
359+ then set this to None .
358360 """
359361 # Check if py or ipy need to be disabled in this instance
360362 if not include_py :
@@ -996,7 +998,9 @@ def _register_subcommands(self, cmdset: Union[CommandSet, 'Cmd']) -> None:
996998 f"Could not find argparser for command '{ command_name } ' needed by subcommand: { method } "
997999 )
9981000
999- def find_subcommand (action : argparse .ArgumentParser , subcmd_names : list [str ]) -> argparse .ArgumentParser :
1001+ def find_subcommand (
1002+ action : argparse .ArgumentParser , subcmd_names : MutableSequence [str ]
1003+ ) -> argparse .ArgumentParser :
10001004 if not subcmd_names :
10011005 return action
10021006 cur_subcmd = subcmd_names .pop (0 )
@@ -2766,7 +2770,7 @@ def _run_cmdfinalization_hooks(self, stop: bool, statement: Statement | None) ->
27662770
27672771 def runcmds_plus_hooks (
27682772 self ,
2769- cmds : list [HistoryItem ] | list [str ],
2773+ cmds : Iterable [HistoryItem ] | Iterable [str ],
27702774 * ,
27712775 add_to_history : bool = True ,
27722776 stop_on_keyboard_interrupt : bool = False ,
@@ -3169,7 +3173,7 @@ def default(self, statement: Statement) -> bool | None:
31693173 self .perror (err_msg , style = None )
31703174 return None
31713175
3172- def completedefault (self , * _ignored : list [str ]) -> Completions :
3176+ def completedefault (self , * _ignored : Sequence [str ]) -> Completions :
31733177 """Call to complete an input line when no command-specific complete_*() method is available.
31743178
31753179 This method is only called for non-argparse-based commands.
@@ -3185,7 +3189,7 @@ def read_input(
31853189 self ,
31863190 prompt : str = '' ,
31873191 * ,
3188- history : list [str ] | None = None ,
3192+ history : Iterable [str ] | None = None ,
31893193 completion_mode : utils .CompletionMode = utils .CompletionMode .NONE ,
31903194 preserve_quotes : bool = False ,
31913195 choices : Iterable [Any ] | None = None ,
@@ -3198,7 +3202,7 @@ def read_input(
31983202 Also supports completion and up-arrow history while input is being entered.
31993203
32003204 :param prompt: prompt to display to user
3201- :param history: optional list of strings to use for up-arrow history. If completion_mode is
3205+ :param history: optional Iterable of strings to use for up-arrow history. If completion_mode is
32023206 CompletionMode.COMMANDS and this is None, then cmd2's command list history will
32033207 be used. The passed in history will not be edited. It is the caller's responsibility
32043208 to add the returned input to history if desired. Defaults to None.
@@ -3873,7 +3877,7 @@ def complete_help_command(self, text: str, line: str, begidx: int, endidx: int)
38733877 return self .basic_complete (text , line , begidx , endidx , strs_to_match )
38743878
38753879 def complete_help_subcommands (
3876- self , text : str , line : str , begidx : int , endidx : int , arg_tokens : dict [str , list [str ]]
3880+ self , text : str , line : str , begidx : int , endidx : int , arg_tokens : Mapping [str , Sequence [str ]]
38773881 ) -> Completions :
38783882 """Completes the subcommands argument of help."""
38793883 # Make sure we have a command whose subcommands we will complete
@@ -4014,13 +4018,13 @@ def do_help(self, args: argparse.Namespace) -> None:
40144018 self .perror (err_msg , style = None )
40154019 self .last_result = False
40164020
4017- def print_topics (self , header : str , cmds : list [str ] | None , cmdlen : int , maxcol : int ) -> None : # noqa: ARG002
4021+ def print_topics (self , header : str , cmds : Sequence [str ] | None , cmdlen : int , maxcol : int ) -> None : # noqa: ARG002
40184022 """Print groups of commands and topics in columns and an optional header.
40194023
40204024 Override of cmd's print_topics() to use Rich.
40214025
40224026 :param header: string to print above commands being printed
4023- :param cmds: list of topics to print
4027+ :param cmds: Sequence of topics to print
40244028 :param cmdlen: unused, even by cmd's version
40254029 :param maxcol: max number of display columns to fit into
40264030 """
@@ -4039,7 +4043,7 @@ def print_topics(self, header: str, cmds: list[str] | None, cmdlen: int, maxcol:
40394043 self .columnize (cmds , maxcol )
40404044 self .poutput ()
40414045
4042- def _print_documented_command_topics (self , header : str , cmds : list [str ], verbose : bool ) -> None :
4046+ def _print_documented_command_topics (self , header : str , cmds : Sequence [str ], verbose : bool ) -> None :
40434047 """Print topics which are documented commands, switching between verbose or traditional output."""
40444048 import io
40454049
@@ -4103,14 +4107,14 @@ def _print_documented_command_topics(self, header: str, cmds: list[str], verbose
41034107 self .poutput (category_grid , soft_wrap = False )
41044108 self .poutput ()
41054109
4106- def render_columns (self , str_list : list [str ] | None , display_width : int = 80 ) -> str :
4110+ def render_columns (self , str_list : Sequence [str ] | None , display_width : int = 80 ) -> str :
41074111 """Render a list of single-line strings as a compact set of columns.
41084112
41094113 This method correctly handles strings containing ANSI style sequences and
41104114 full-width characters (like those used in CJK languages). Each column is
41114115 only as wide as necessary and columns are separated by two spaces.
41124116
4113- :param str_list: list of single-line strings to display
4117+ :param str_list: Sequence of single-line strings to display
41144118 :param display_width: max number of display columns to fit into
41154119 :return: a string containing the columnized output
41164120 """
@@ -4162,14 +4166,14 @@ def render_columns(self, str_list: list[str] | None, display_width: int = 80) ->
41624166
41634167 return "\n " .join (rows )
41644168
4165- def columnize (self , str_list : list [str ] | None , display_width : int = 80 ) -> None :
4169+ def columnize (self , str_list : Sequence [str ] | None , display_width : int = 80 ) -> None :
41664170 """Display a list of single-line strings as a compact set of columns.
41674171
41684172 Override of cmd's columnize() that uses the render_columns() method.
41694173 The method correctly handles strings with ANSI style sequences and
41704174 full-width characters (like those used in CJK languages).
41714175
4172- :param str_list: list of single-line strings to display
4176+ :param str_list: Sequence of single-line strings to display
41734177 :param display_width: max number of display columns to fit into
41744178 """
41754179 columnized_strs = self .render_columns (str_list , display_width )
@@ -4220,7 +4224,7 @@ def do_quit(self, _: argparse.Namespace) -> bool | None:
42204224 self .last_result = True
42214225 return True
42224226
4223- def select (self , opts : str | list [str ] | list [tuple [Any , str | None ]], prompt : str = 'Your choice? ' ) -> Any :
4227+ def select (self , opts : str | Iterable [str ] | Iterable [tuple [Any , str | None ]], prompt : str = 'Your choice? ' ) -> Any :
42244228 """Present a numbered menu to the user.
42254229
42264230 Modeled after the bash shell's SELECT. Returns the item chosen.
@@ -4233,7 +4237,7 @@ def select(self, opts: str | list[str] | list[tuple[Any, str | None]], prompt: s
42334237 that the return value can differ from
42344238 the text advertised to the user
42354239 """
4236- local_opts : list [str ] | list [tuple [Any , str | None ]]
4240+ local_opts : Iterable [str ] | Iterable [tuple [Any , str | None ]]
42374241 if isinstance (opts , str ):
42384242 local_opts = cast (list [tuple [Any , str | None ]], list (zip (opts .split (), opts .split (), strict = False )))
42394243 else :
@@ -4295,7 +4299,7 @@ def _build_base_set_parser(cls) -> Cmd2ArgumentParser:
42954299 return base_set_parser
42964300
42974301 def complete_set_value (
4298- self , text : str , line : str , begidx : int , endidx : int , arg_tokens : dict [str , list [str ]]
4302+ self , text : str , line : str , begidx : int , endidx : int , arg_tokens : Mapping [str , Sequence [str ]]
42994303 ) -> Completions :
43004304 """Completes the value argument of set."""
43014305 param = arg_tokens ['param' ][0 ]
0 commit comments