From 913210950b36cea8b5d8ad3afccbad126a9033a3 Mon Sep 17 00:00:00 2001 From: neoniobium Date: Wed, 24 Dec 2025 11:08:03 +0100 Subject: [PATCH] [typing] use less restrictive type hints for some public methodes --- cmd2/cmd2.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 60a0ccf5..ab7c697e 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -48,6 +48,7 @@ Callable, Iterable, Mapping, + Sequence, ) from types import ( FrameType, @@ -320,10 +321,10 @@ def __init__( include_py: bool = False, include_ipy: bool = False, allow_cli_args: bool = True, - transcript_files: list[str] | None = None, + transcript_files: Sequence[str] | None = None, allow_redirection: bool = True, - multiline_commands: list[str] | None = None, - terminators: list[str] | None = None, + multiline_commands: Iterable[str] | None = None, + terminators: Iterable[str] | None = None, shortcuts: dict[str, str] | None = None, command_sets: Iterable[CommandSet] | None = None, auto_load_commands: bool = False, @@ -568,7 +569,7 @@ def __init__( elif callargs: self._startup_commands.extend(callargs) elif transcript_files: - self._transcript_files = transcript_files + self._transcript_files = list(transcript_files) # Set the pager(s) for use when displaying output using a pager if sys.platform.startswith('win'): @@ -2870,7 +2871,7 @@ def _run_cmdfinalization_hooks(self, stop: bool, statement: Statement | None) -> def runcmds_plus_hooks( self, - cmds: list[HistoryItem] | list[str], + cmds: Iterable[HistoryItem] | Iterable[str], *, add_to_history: bool = True, stop_on_keyboard_interrupt: bool = False, @@ -4218,7 +4219,7 @@ def do_help(self, args: argparse.Namespace) -> None: self.perror(err_msg, style=None) self.last_result = False - def print_topics(self, header: str, cmds: list[str] | None, cmdlen: int, maxcol: int) -> None: # noqa: ARG002 + def print_topics(self, header: str, cmds: Sequence[str] | None, cmdlen: int, maxcol: int) -> None: # noqa: ARG002 """Print groups of commands and topics in columns and an optional header. Override of cmd's print_topics() to use Rich. @@ -4307,7 +4308,7 @@ def _print_documented_command_topics(self, header: str, cmds: list[str], verbose self.poutput(category_grid) self.poutput() - def render_columns(self, str_list: list[str] | None, display_width: int = 80) -> str: + def render_columns(self, str_list: Sequence[str] | None, display_width: int = 80) -> str: """Render a list of single-line strings as a compact set of columns. This method correctly handles strings containing ANSI style sequences and @@ -4366,7 +4367,7 @@ def render_columns(self, str_list: list[str] | None, display_width: int = 80) -> return "\n".join(rows) - def columnize(self, str_list: list[str] | None, display_width: int = 80) -> None: + def columnize(self, str_list: Sequence[str] | None, display_width: int = 80) -> None: """Display a list of single-line strings as a compact set of columns. Override of cmd's columnize() that uses the render_columns() method.