summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorSteven Bethard <steven.bethard@gmail.com>2011-03-26 16:33:56 (GMT)
committerSteven Bethard <steven.bethard@gmail.com>2011-03-26 16:33:56 (GMT)
commit8d9a4628c35811a803bde626c76573c722beea03 (patch)
treee0686d31fd643b760904ac3b0bcee9e900554f74 /Lib/argparse.py
parent633872e3fbfba101dcae0fb1d6938c91e10adafe (diff)
downloadcpython-8d9a4628c35811a803bde626c76573c722beea03.zip
cpython-8d9a4628c35811a803bde626c76573c722beea03.tar.gz
cpython-8d9a4628c35811a803bde626c76573c722beea03.tar.bz2
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.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index de3cd11..e46f919 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):