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 | 8d9a4628c35811a803bde626c76573c722beea03 (patch) | |
tree | e0686d31fd643b760904ac3b0bcee9e900554f74 /Lib/argparse.py | |
parent | 633872e3fbfba101dcae0fb1d6938c91e10adafe (diff) | |
download | cpython-git-8d9a4628c35811a803bde626c76573c722beea03.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): |