gh-142332: Fix usage formatting for positional arguments in mutually exclusive groups in argparse (GH-142333)

This commit is contained in:
Serhiy Storchaka 2025-12-06 20:03:45 +02:00 committed by GitHub
parent 5be3405e4e
commit 70c27ce94b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 7 deletions

View file

@ -467,16 +467,12 @@ def _get_actions_usage_parts_with_split(self, actions, groups, opt_count=None):
# produce all arg strings
elif not action.option_strings:
default = self._get_default_metavar_for_positional(action)
part = (
t.summary_action
+ self._format_args(action, default)
+ t.reset
)
part = self._format_args(action, default)
# if it's in a group, strip the outer []
if action in group_actions:
if part[0] == '[' and part[-1] == ']':
part = part[1:-1]
part = t.summary_action + part + t.reset
# produce the first way to invoke the option in brackets
else: