Title: argparse: auto-generated synopsis omits REMAINDER argument
Type: Stage:
Components: Library (Lib) Versions: Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: rrt
Priority: normal Keywords:

Created on 2020-09-24 23:40 by rrt, last changed 2020-09-24 23:42 by rrt.

Messages (2)
msg377469 - (view) Author: Reuben Thomas (rrt) Date: 2020-09-24 23:40
Consider the following example from the Python documentation:

>>> parser = argparse.ArgumentParser(prog='PROG')
>>> parser.add_argument('--foo')
>>> parser.add_argument('command')
>>> parser.add_argument('args', nargs=argparse.REMAINDER)

Now show the help:

>>> parser.parse_args(['-h'])

This prints:

usage: PROG [-h] [--foo FOO] command ...

positional arguments:

Note that "args" is not shown in the synopsis. I suggest that the synopsis should instead say:

usage: PROG [-h] [--foo FOO] command args...
msg377470 - (view) Author: Reuben Thomas (rrt) Date: 2020-09-24 23:42
A workaround to help users for now is:

>>> parser.add_argument('args', metavar='...', nargs=argparse.REMAINDER)

as then at least the help entry corresponds to the synopsis:

positional arguments:

And with a `help` string, this can be clarified further, e.g.:

>>> parser.add_argument('args', metavar='...', nargs=argparse.REMAINDER, help='arguments to the command')
Date User Action Args
2020-09-24 23:42:31rrtsetmessages: + msg377470
2020-09-24 23:40:02rrtcreate