-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
argparse.BooleanOptionalAction with default=argparse.SUPPRESS and help specified raises exception #90238
Comments
When argparse.BooleanOptionalAction is used with default=argparse.SUPPRESS and help is specified, trying to display --help results in a crash. Reproducer: import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--test', action=argparse.BooleanOptionalAction, default=argparse.SUPPRESS, help='Foo')
parser.parse_args() Result when running 'python t.py --help': Traceback (most recent call last):
File "/path/to/t.py", line 4, in <module>
parser.parse_args()
File "/usr/lib/python3.10/argparse.py", line 1821, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "/usr/lib/python3.10/argparse.py", line 1854, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
File "/usr/lib/python3.10/argparse.py", line 2063, in _parse_known_args
start_index = consume_optional(start_index)
File "/usr/lib/python3.10/argparse.py", line 2003, in consume_optional
take_action(action, args, option_string)
File "/usr/lib/python3.10/argparse.py", line 1931, in take_action
action(self, namespace, argument_values, option_string)
File "/usr/lib/python3.10/argparse.py", line 1095, in __call__
parser.print_help()
File "/usr/lib/python3.10/argparse.py", line 2551, in print_help
self._print_message(self.format_help(), file)
File "/usr/lib/python3.10/argparse.py", line 2535, in format_help
return formatter.format_help()
File "/usr/lib/python3.10/argparse.py", line 283, in format_help
help = self._root_section.format_help()
File "/usr/lib/python3.10/argparse.py", line 214, in format_help
item_help = join([func(*args) for func, args in self.items])
File "/usr/lib/python3.10/argparse.py", line 214, in <listcomp>
item_help = join([func(*args) for func, args in self.items])
File "/usr/lib/python3.10/argparse.py", line 214, in format_help
item_help = join([func(*args) for func, args in self.items])
File "/usr/lib/python3.10/argparse.py", line 214, in <listcomp>
item_help = join([func(*args) for func, args in self.items])
File "/usr/lib/python3.10/argparse.py", line 530, in _format_action
help_text = self._expand_help(action)
File "/usr/lib/python3.10/argparse.py", line 627, in _expand_help
return self._get_help_string(action) % params
KeyError: 'default' The problem is that in Line 879 in f54fee7
(I've experienced the crash with Python 3.9 and 3.10; the test I've created also crashes for the current main branch, so I guess that means that Python 3.11 is also affected. I haven't tested older Python versions before 3.9.) |
Changing type. Crash is typically segfault or hang in c code rather than an exception. |
Thanks for the report and the PR, Felix! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: