Skip to content

Commit e558e4b

Browse files
committed
Fixed mypy 2.2.0 failures
mypy 2.2.0 updated its typeshed definitions for argparse.ArgumentParser to align with recent updates to the standard library in newer Python versions (such as the addition of the file argument for output coloring and the optional formatter parameter). These new type stub signatures broke our overrides in cmd2/argparse_utils.py: - _get_formatter failed because the typeshed stub specifies it can accept an optional parameter file positionally, but our override only captured keyword arguments (**_kwargs: Any). - format_help failed because our override strictly took no arguments (def format_help(self)), while the base class accepts formatter.
1 parent aca7d06 commit e558e4b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

cmd2/argparse_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,13 +1035,13 @@ def error(self, message: str) -> NoReturn:
10351035

10361036
self.exit(2, f"{formatted_message}\n")
10371037

1038-
def _get_formatter(self, **_kwargs: Any) -> Cmd2HelpFormatter:
1038+
def _get_formatter(self, *_args: Any, **_kwargs: Any) -> Cmd2HelpFormatter:
10391039
"""Override with customizations for Cmd2HelpFormatter."""
10401040
return self.formatter_class(prog=self.prog, file=self._thread_locals.current_output_file)
10411041

1042-
def format_help(self) -> str:
1042+
def format_help(self, *args: Any, **kwargs: Any) -> str:
10431043
"""Override to add a newline."""
1044-
return super().format_help() + "\n"
1044+
return super().format_help(*args, **kwargs) + "\n"
10451045

10461046
def _get_nargs_pattern(self, action: argparse.Action) -> str:
10471047
"""Override to support nargs ranges."""

0 commit comments

Comments
 (0)