Skip to content

argparse wrongly claims '*' positional argument is required in error output #137439

@moi90

Description

@moi90

Bug report

Bug description:

While this issue has been fixed for the top-level parser (#72795), it still exists in sub-parsers. This test case (added to test_argparse.py) fails:

def test_subparser_required_args_zero_or_more(self):
    sub_parsers = self.parser.add_subparsers()
    sub_parser = sub_parsers.add_parser('sub')

    sub_parser.add_argument('bar')
    sub_parser.add_argument('baz', nargs='*')
    self.assertRaisesRegex(argparse.ArgumentError,
                            'the following arguments are required: bar$',
                            self.parser.parse_args, ["sub"])

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Doc issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions