This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2020-09-24 23:40 by rrt, last changed 2022-04-11 14:59 by admin.

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:
  command
  args

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:
  command
  ...

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')
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86022
2020-09-24 23:42:31rrtsetmessages: + msg377470
2020-09-24 23:40:02rrtcreate