daniel hahler added the comment:
This adds overhead, since it creates a formatter and uses it for formatting
only for validation purposes.
I think it is better to only have the error when the formatter is actually used
(i.e. the help is displayed - which is not the typical use case, and it
Roundup Robot devnull@devnull added the comment:
New changeset c89db9b36ea6 by Steven Bethard in branch '3.2':
Issue #9348: Raise an early error if argparse nargs and metavar don't match.
http://hg.python.org/cpython/rev/c89db9b36ea6
New changeset b93a50bb74f2 by Steven Bethard in branch
Steven Bethard steven.beth...@gmail.com added the comment:
Thanks for the patch. I used something similar to what you proposed, but
instead of creating a local formatter, I just call self._get_formatter() if it
exists.
--
assignee: - bethard
nosy: -python-dev
resolution: - fixed
Denver Coneybeare denver.coneybe...@gmail.com added the comment:
Awesome, thanks for committing the patch. Glad I could help.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9348
___
Denver Coneybeare denver.coneybe...@gmail.com added the comment:
For kicks, I just took a look at this old, forgotten issue. I agree with the
submitter that add_argument() should fail if nargs and metavar do not match,
instead of having format_help() raise the exception later on.
I've
Steven Bethard steven.beth...@gmail.com added the comment:
You can specify either 1 or N. So for n=3, you can specify metavar=X or
metavar=(X, Y, Z) but not metavar=(X, Y). The special nargs value ?
always takes only one, while * and + always take two. (This makes sense if
you think about how
Catherine Devlin fredv8vi...@liquidid.net added the comment:
Thanks for the correction, Steven. This unit test matches your description.
Use it instead of my earlier submission.
--
Added file: http://bugs.python.org/file18390/wrong_metavars_test_corrected.patch
Catherine Devlin fredv8vi...@liquidid.net added the comment:
I'm attaching a unit test patch that does something vaguely like Steven
suggests. It definitely needs review.
Also, I'm assuming that it's OK to specify *fewer* metavars than nargs, just
not more... but I'm not sure about that.
New submission from Steven Bethard steven.beth...@gmail.com:
What steps will reproduce the problem?
parser = argparse.ArgumentParser()
parser.add_argument('--foo', nargs=2, metavar=('X','Y','Z'))
parser.parse_args(['-h'])
The error dosn't show up until help is formatted.
Giving any