Skip to content

gh-95889: Implement Default Value Display in ArgumentsDefaultsHelpFormatter Help Message #112682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def _format_action(self, action):
action_header = self._format_action_invocation(action)

# no help; start on same line and add a final newline
if not action.help:
if action.help is None:
tup = self._current_indent, '', action_header
action_header = '%*s%s\n' % tup

Expand All @@ -538,7 +538,7 @@ def _format_action(self, action):
parts = [action_header]

# if there was help for the action, add lines of help text
if action.help and action.help.strip():
if action.help is not None and action.help.strip():
help_text = self._expand_help(action)
if help_text:
help_lines = self._split_lines(help_text, help_width)
Expand Down Expand Up @@ -701,6 +701,11 @@ class ArgumentDefaultsHelpFormatter(HelpFormatter):
provided by the class are considered an implementation detail.
"""

def add_argument(self, *args, **kwargs):
if args[0].help is None:
args[0].help = 'No description'
super().add_argument(*args, **kwargs)

def _get_help_string(self, action):
"""
Add the default value to the option help message.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the default description for every argument in ArgumentsDefaultsHelpFormatter to ensure the default values of arguments are displayed in the help message.