[New-bugs-announce] [issue16970] argparse: bad nargs value raises misleading message
Chris Jerdonek
report at bugs.python.org
Tue Jan 15 13:09:51 CET 2013
New submission from Chris Jerdonek:
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('foo', nargs='a')
...
File ".../Lib/argparse.py", line 1333, in add_argument
raise ValueError("length of metavar tuple does not match nargs")
ValueError: length of metavar tuple does not match nargs
The message should really be about nargs not having a valid value. The nargs value is invalid regardless of the metavar. There is also this:
>>> parser.add_argument('foo', nargs=-1)
_StoreAction(option_strings=[], dest='foo', nargs=-1, const=None, default=None, type=None, choices=None, help=None, metavar=None)
which is not consistent with this:
>>> parser.add_argument('foo', nargs=0)
...
raise ValueError('nargs for store actions must be > 0; if you '
ValueError: nargs for store actions must be > 0; if you have nothing to store, actions such as store true or store const may be more appropriate
----------
components: Library (Lib)
keywords: easy
messages: 180012
nosy: bethard, chris.jerdonek
priority: normal
severity: normal
stage: needs patch
status: open
title: argparse: bad nargs value raises misleading message
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16970>
_______________________________________
More information about the New-bugs-announce
mailing list