Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incomplete error testing for nargs #59

Closed
hpaulj opened this issue Apr 25, 2013 · 1 comment
Closed

incomplete error testing for nargs #59

hpaulj opened this issue Apr 25, 2013 · 1 comment

Comments

@hpaulj
Copy link

hpaulj commented Apr 25, 2013

Several python issues deal with nargs related error messages:

http://bugs.python.org/issue16970 argparse: bad nargs value raises misleading message

http://bugs.python.org/issue9849 Argparse needs better error handling for nargs

nargs can be one of several strings, e.g. '*', '...' (Const.PARSER) or an integer. But checking for valid values is ad hoc.

One issue is when or where nargs can be 0 or <0

parser.addArgument('foo',{nargs:0})

triggers an error by _StoreAction, saying that nargs should be >0. However

parser.addArgument('foo',{nargs:-1})

is accepted. parser.parseArgs([]) returns { foo: [] }, but formatUsage has problems formatting a metavar (in Javascript, not in the Python).

Another issue is what happens if nargs isn't one of the recognized strings or an integer (e.g. nargs:'1' or nargs:'test'). Neither Python or Javascript raises an error in addArgument. Instead the problems arise in either parseArgs or formatHelp. In both the ultimate issue is whether it can replicate a string nargs times.

In the most recent Python release, addArgument does test whether a tuple metavar matches nargs, and in the process discovers invalid nargs values. But even with this the error messages are not clear. Also parser.addArgument gets this test, but group.addArgument does not.

@rlidwka
Copy link
Member

rlidwka commented Aug 14, 2020

I've ported everything from scratch based on python 3.9 (to be released as argparse version 2.0), it should give out the same errors as python.

This hasn't been fully fixed in python yet. We're gonna port it when they do, but until then please bug python devs to fix it over there.

PS: what does nargs=-1 even mean?

@rlidwka rlidwka closed this as completed Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants