Skip to content

Commit 0fd1255

Browse files
committed
Fixed handling of argparse's default optionals group name that was changed in Python 3.10
1 parent 279cfda commit 0fd1255

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.1.1 (TBD, 2021)
2+
* Bug Fixes
3+
* Fixed handling of argparse's default optionals group name that was changed in Python 3.10
4+
15
## 2.1.0 (June 14, 2021)
26
* Enhancements
37
* Converted persistent history files from pickle to compressed JSON

cmd2/argparse_custom.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,14 @@ def format_help(self) -> str:
973973

974974
# Begin cmd2 customization (separate required and optional arguments)
975975

976+
if sys.version_info >= (3, 10):
977+
default_optionals_title = 'options'
978+
else:
979+
default_optionals_title = 'optional arguments'
980+
976981
# positionals, optionals and user-defined groups
977982
for action_group in self._action_groups:
978-
if action_group.title == 'optional arguments':
983+
if action_group.title == default_optionals_title:
979984
# check if the arguments are required, group accordingly
980985
req_args = []
981986
opt_args = []
@@ -992,7 +997,7 @@ def format_help(self) -> str:
992997
formatter.end_section()
993998

994999
# now display truly optional arguments
995-
formatter.start_section(action_group.title)
1000+
formatter.start_section('optional arguments')
9961001
formatter.add_text(action_group.description)
9971002
formatter.add_arguments(opt_args)
9981003
formatter.end_section()

cmd2/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ def __init__(
131131
validation using str_to_bool(). The val_type function should raise an exception if it fails.
132132
This exception will be caught and printed by Cmd.do_set().
133133
:param description: string describing this setting
134-
:param settable_object: Object to configure with the set command
135-
:param settable_attrib_name: Attribute name to be modified. Defaults to `name` if not specified.
134+
:param settable_object: object to which the instance attribute belongs (e.g. self)
135+
:param settable_attrib_name: name which displays to the user in the output of the set command.
136+
Defaults to `name` if not specified.
136137
:param onchange_cb: optional function or method to call when the value of this settable is altered
137138
by the set command. (e.g. onchange_cb=self.debug_changed)
138139

0 commit comments

Comments
 (0)