-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
Bug report
When using an optional argument with nargs=argparse.REMAINDER, the argument appears within the list of optional arguments and before any positional arguments. I expected it to be placed last in usage line, which would better match the behavior since it consumes any following parameters. Not sure it is really bug...
The following scripts shows the issue:
#!/usr/bin/env python
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('foo')
parser.add_argument('--extra', nargs=argparse.REMAINDER)
parser.add_argument('--option')
args = parser.parse_args()
[--extra ...] is not at all last in the usage line:
$ ./test.py -h
usage: test.py [-h] [--extra ...] [--option OPTION] foo
positional arguments:
foo
options:
-h, --help show this help message and exit
--extra ...
--option OPTION
Your environment
- archlinux/amd64
- Tested on python 3.10.4 and also on 3.7.7 and 3.8.7.
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Projects
Status
Features