Skip to content

Commit 6a46a63

Browse files
committed
Fixed handling of argparse's default options group name which was changed in Python 3.10
1 parent 279cfda commit 6a46a63

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
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 options group name which 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
@@ -975,7 +975,12 @@ def format_help(self) -> str:
975975

976976
# positionals, optionals and user-defined groups
977977
for action_group in self._action_groups:
978-
if action_group.title == 'optional arguments':
978+
if sys.version_info >= (3, 10):
979+
default_options_group = action_group.title == 'options'
980+
else:
981+
default_options_group = action_group.title == 'optional arguments'
982+
983+
if default_options_group:
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

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
# General information about the project.
5454
project = 'cmd2'
55-
copyright = '2010-2020, cmd2 contributors'
55+
copyright = '2010-2021, cmd2 contributors'
5656
author = 'cmd2 contributors'
5757

5858
# The version info for the project you're documenting, acts as replacement for

0 commit comments

Comments
 (0)