New submission from Steven Bethard <[email protected]>:
>From a private email in respect to the following class of error messages:
>>> parser = argparse.ArgumentParser(prog='PROG')
>>> parser.add_argument('--foo')
>>> parser.add_argument('--bar')
>>> parser.add_argument('ham')
>>> parser.add_argument('spam', nargs='+')
>>> parser.parse_args(['HAM'])
usage: PROG [-h] [--foo FOO] [--bar BAR] ham spam [spam ...]
PROG: error: too few arguments
----------------------------------------------------------------------
One suggestion would be that when it displays the error "too few arguments", it
would nice if it said something about the argument(s) that are missing.
I modified argparse's error message when there are too few arguments. I didn't
examine the code a lot, so there might be cases where this doesn't work, but
here's what I did:
if positionals:
self.error(_('too few arguments: %s is required' % positionals[0].dest))
----------------------------------------------------------------------
This would be a nice feature - I haven't checked if the suggested approach
works in general though.
----------
components: Library (Lib)
messages: 121220
nosy: bethard
priority: normal
severity: normal
stage: needs patch
status: open
title: better error message from argparse when positionals missing
versions: Python 3.2
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue10424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com