Issue #9348: Raise an early error if argparse nargs and metavar don't match.

This commit is contained in:
Steven Bethard 2011-03-26 17:33:56 +01:00
parent 633872e3fb
commit 8d9a4628c3
3 changed files with 180 additions and 0 deletions

View file

@ -1294,6 +1294,13 @@ class _ActionsContainer(object):
if not _callable(type_func):
raise ValueError('%r is not callable' % type_func)
# raise an error if the metavar does not match the type
if hasattr(self, "_get_formatter"):
try:
self._get_formatter()._format_args(action, None)
except TypeError:
raise ValueError("length of metavar tuple does not match nargs")
return self._add_action(action)
def add_argument_group(self, *args, **kwargs):