GH-64532: Include parent's required optional arguments in subparser usage (#142355)

This commit is contained in:
Savannah Ostrowski 2025-12-06 10:30:50 -08:00 committed by GitHub
parent 70c27ce94b
commit 0ed56ed88f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View file

@ -2770,6 +2770,16 @@ def test_optional_subparsers(self):
ret = parser.parse_args(())
self.assertIsNone(ret.command)
def test_subparser_help_with_parent_required_optional(self):
parser = ErrorRaisingArgumentParser(prog='PROG')
parser.add_argument('--foo', required=True)
parser.add_argument('--bar')
subparsers = parser.add_subparsers()
parser_sub = subparsers.add_parser('sub')
parser_sub.add_argument('arg')
self.assertEqual(parser_sub.format_usage(),
'usage: PROG --foo FOO sub [-h] arg\n')
def test_help(self):
self.assertEqual(self.parser.format_usage(),
'usage: PROG [-h] [--foo] bar {1,2,3} ...\n')