Skip to content

argparse incorrectly says arguments are required #103219

Closed as not planned
Closed as not planned
@eslindsey

Description

@eslindsey

When using nargs='*' with other required arguments, argparse incorrectly says the optional argument is required.

Output (with no arguments)

usage: example [-h] foo [bar ...]
example: error: the following arguments are required: foo, bar

Code

import argparse

parser = argparse.ArgumentParser(prog='example')
parser.add_argument('foo')
parser.add_argument('bar', nargs='*')
args = parser.parse_args()

Python 3.9.16

Linked PRs

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