-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Labels
3.10only security fixesonly security fixes3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.9only security fixesonly security fixeseasystdlibPython modules in the Lib dirPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
In the code below, it is valid to supply no arguments.
from argparse import ArgumentParser
p = ArgumentParser()
p.add_argument('dessert', nargs='*', choices=('cake', 'pie'))
p.parse_args([])
However, the following error is generated:
usage: tmp5.py [-h] [{cake,pie} ...]
tmp5.py: error: argument dessert: invalid choice: [] (choose from 'cake', 'pie')
What is happening is that the empty list is being treated a value rather than a collection of values.
Metadata
Metadata
Assignees
Labels
3.10only security fixesonly security fixes3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.9only security fixesonly security fixeseasystdlibPython modules in the Lib dirPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Doc issues