Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 22 additions & 34 deletions cmd2/argparse_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,42 +1215,30 @@
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
"""
kwargs: 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
)
kwargs = {

Check warning on line 1221 in cmd2/argparse_custom.py

View check run for this annotation

Codecov / codecov/patch

cmd2/argparse_custom.py#L1221

Added line #L1221 was not covered by tests
"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
**kwargs, # added in Python 3.14
)

self.set_ap_completer_type(ap_completer_type) # type: ignore[attr-defined]

Expand Down
Loading