diff options
| author | Steven Bethard <steven.bethard@gmail.com> | 2011-03-26 17:33:56 +0100 |
|---|---|---|
| committer | Steven Bethard <steven.bethard@gmail.com> | 2011-03-26 17:33:56 +0100 |
| commit | 6dbb38b1e41a6cd53bed67e6b3720fac667d8fe8 (patch) | |
| tree | b2d2d66e2e9e2bb4a8d499eb7eb63fb71637fa88 /Lib/argparse.py | |
| parent | 8bdceddda84c4dd9cc67e79e5fcec9f871e3e0c6 (diff) | |
| download | cpython-6dbb38b1e41a6cd53bed67e6b3720fac667d8fe8.tar.gz | |
Issue #9348: Raise an early error if argparse nargs and metavar don't match.
Diffstat (limited to 'Lib/argparse.py')
| -rw-r--r-- | Lib/argparse.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py index de3cd11479..e46f919e02 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -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): |
