From c7a3a9f99baca3a8c7dc9479fef91d4c765a596d Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Thu, 26 Jun 2025 15:57:46 -0400 Subject: [PATCH 1/2] Simplify Python 3.14 check in argparse_custom.py --- cmd2/argparse_custom.py | 56 ++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/cmd2/argparse_custom.py b/cmd2/argparse_custom.py index fd103685..1d454fdc 100644 --- a/cmd2/argparse_custom.py +++ b/cmd2/argparse_custom.py @@ -1215,42 +1215,30 @@ def __init__( behavior on this parser. If this is None or not present, then cmd2 will use argparse_completer.DEFAULT_AP_COMPLETER when tab completing this parser's arguments """ + kw_args: dict[str, bool] = {} if sys.version_info >= (3, 14): # Python >= 3.14 so pass new arguments to parent argparse.ArgumentParser class - super().__init__( - prog=prog, - usage=usage, - description=description, - epilog=epilog, - parents=parents if parents else [], - formatter_class=formatter_class, # type: ignore[arg-type] - prefix_chars=prefix_chars, - fromfile_prefix_chars=fromfile_prefix_chars, - argument_default=argument_default, - conflict_handler=conflict_handler, - add_help=add_help, - allow_abbrev=allow_abbrev, - exit_on_error=exit_on_error, # added in Python 3.9 - suggest_on_error=suggest_on_error, # added in Python 3.14 - color=color, # added in Python 3.14 - ) - else: - # Python < 3.14, so don't pass new arguments to parent argparse.ArgumentParser class - super().__init__( - prog=prog, - usage=usage, - description=description, - epilog=epilog, - parents=parents if parents else [], - formatter_class=formatter_class, # type: ignore[arg-type] - prefix_chars=prefix_chars, - fromfile_prefix_chars=fromfile_prefix_chars, - argument_default=argument_default, - conflict_handler=conflict_handler, - add_help=add_help, - allow_abbrev=allow_abbrev, - exit_on_error=exit_on_error, # added in Python 3.9 - ) + kw_args = { + "suggest_on_error": suggest_on_error, + "color": color, + } + + super().__init__( + prog=prog, + usage=usage, + description=description, + epilog=epilog, + parents=parents if parents else [], + formatter_class=formatter_class, # type: ignore[arg-type] + prefix_chars=prefix_chars, + fromfile_prefix_chars=fromfile_prefix_chars, + argument_default=argument_default, + conflict_handler=conflict_handler, + add_help=add_help, + allow_abbrev=allow_abbrev, + exit_on_error=exit_on_error, # added in Python 3.9 + **kw_args, # added in Python 3.14 + ) self.set_ap_completer_type(ap_completer_type) # type: ignore[attr-defined] From a7a8a035e8988c424cab35ad4d4d27db57609009 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Thu, 26 Jun 2025 16:11:25 -0400 Subject: [PATCH 2/2] Renamed `kw_args` to `kwargs` for idomatic consistency --- cmd2/argparse_custom.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd2/argparse_custom.py b/cmd2/argparse_custom.py index 1d454fdc..01eea688 100644 --- a/cmd2/argparse_custom.py +++ b/cmd2/argparse_custom.py @@ -1215,10 +1215,10 @@ def __init__( behavior on this parser. If this is None or not present, then cmd2 will use argparse_completer.DEFAULT_AP_COMPLETER when tab completing this parser's arguments """ - kw_args: dict[str, bool] = {} + kwargs: dict[str, bool] = {} if sys.version_info >= (3, 14): # Python >= 3.14 so pass new arguments to parent argparse.ArgumentParser class - kw_args = { + kwargs = { "suggest_on_error": suggest_on_error, "color": color, } @@ -1237,7 +1237,7 @@ def __init__( add_help=add_help, allow_abbrev=allow_abbrev, exit_on_error=exit_on_error, # added in Python 3.9 - **kw_args, # added in Python 3.14 + **kwargs, # added in Python 3.14 ) self.set_ap_completer_type(ap_completer_type) # type: ignore[attr-defined]