Issue 15433: argparse usage line is wrong - Python tracker

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
process
Status: closed Resolution: duplicate
Dependencies: Superseder: argparse optionals with nargs='?', '*' or '+' can't be followed by positionals
View: 9338
Assigned To: Nosy List: anton.barkovsky, chris.jerdonek, slikts
Priority: normal Keywords:

Created on 2012-07-23 09:48 by slikts, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (1)
msg166217 - (view) Author: Reinis Ivanovs (slikts) Date: 2012-07-23 09:48
I set a positional argument and an optional argument that accepts a list:

> parser = argparse.ArgumentParser()
> parser.add_argument('foo')
> parser.add_argument('-bar', nargs='*')

The usage line I get from --help is this:

> $ example.py --help
> usage: example.py [-h] [-bar [BAR [BAR ...]]] foo

Trying to actually follow the usage instructions produces this error:

> $ example.py -bar x y z
> error: too few arguments

Reversing the argument order works however:

> $ example.py z -bar x y

So the usage instructions are clearly wrong.