mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #9348: Raise an early error if argparse nargs and metavar don't match.
This commit is contained in:
parent
633872e3fb
commit
8d9a4628c3
3 changed files with 180 additions and 0 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue