Skip to content

Commit 2433b2f

Browse files
authored
Simplify Python 3.14 check in argparse_custom.py (#1452)
* Simplify Python 3.14 check in argparse_custom.py * Renamed `kw_args` to `kwargs` for idomatic consistency
1 parent 6aed7cd commit 2433b2f

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

cmd2/argparse_custom.py

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,42 +1215,30 @@ def __init__(
12151215
behavior on this parser. If this is None or not present, then cmd2 will use
12161216
argparse_completer.DEFAULT_AP_COMPLETER when tab completing this parser's arguments
12171217
"""
1218+
kwargs: dict[str, bool] = {}
12181219
if sys.version_info >= (3, 14):
12191220
# Python >= 3.14 so pass new arguments to parent argparse.ArgumentParser class
1220-
super().__init__(
1221-
prog=prog,
1222-
usage=usage,
1223-
description=description,
1224-
epilog=epilog,
1225-
parents=parents if parents else [],
1226-
formatter_class=formatter_class, # type: ignore[arg-type]
1227-
prefix_chars=prefix_chars,
1228-
fromfile_prefix_chars=fromfile_prefix_chars,
1229-
argument_default=argument_default,
1230-
conflict_handler=conflict_handler,
1231-
add_help=add_help,
1232-
allow_abbrev=allow_abbrev,
1233-
exit_on_error=exit_on_error, # added in Python 3.9
1234-
suggest_on_error=suggest_on_error, # added in Python 3.14
1235-
color=color, # added in Python 3.14
1236-
)
1237-
else:
1238-
# Python < 3.14, so don't pass new arguments to parent argparse.ArgumentParser class
1239-
super().__init__(
1240-
prog=prog,
1241-
usage=usage,
1242-
description=description,
1243-
epilog=epilog,
1244-
parents=parents if parents else [],
1245-
formatter_class=formatter_class, # type: ignore[arg-type]
1246-
prefix_chars=prefix_chars,
1247-
fromfile_prefix_chars=fromfile_prefix_chars,
1248-
argument_default=argument_default,
1249-
conflict_handler=conflict_handler,
1250-
add_help=add_help,
1251-
allow_abbrev=allow_abbrev,
1252-
exit_on_error=exit_on_error, # added in Python 3.9
1253-
)
1221+
kwargs = {
1222+
"suggest_on_error": suggest_on_error,
1223+
"color": color,
1224+
}
1225+
1226+
super().__init__(
1227+
prog=prog,
1228+
usage=usage,
1229+
description=description,
1230+
epilog=epilog,
1231+
parents=parents if parents else [],
1232+
formatter_class=formatter_class, # type: ignore[arg-type]
1233+
prefix_chars=prefix_chars,
1234+
fromfile_prefix_chars=fromfile_prefix_chars,
1235+
argument_default=argument_default,
1236+
conflict_handler=conflict_handler,
1237+
add_help=add_help,
1238+
allow_abbrev=allow_abbrev,
1239+
exit_on_error=exit_on_error, # added in Python 3.9
1240+
**kwargs, # added in Python 3.14
1241+
)
12541242

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

0 commit comments

Comments
 (0)