Skip to content

argparse option argument with nargs=argparse.REMAINDER is misplaced in usage line #92625

@dhedde

Description

@dhedde

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

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    Features

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions