Issue #9348: Raise an early error if argparse nargs and metavar don't match. (Merge from 3.2.)

This commit is contained in:
Steven Bethard 2011-03-26 17:35:11 +01:00
commit edbe4c5249
3 changed files with 180 additions and 0 deletions

View file

@ -1319,6 +1319,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):