diff options
author | Steven Bethard <steven.bethard@gmail.com> | 2011-03-26 16:35:11 (GMT) |
---|---|---|
committer | Steven Bethard <steven.bethard@gmail.com> | 2011-03-26 16:35:11 (GMT) |
commit | edbe4c5249cb96dfe55e114de998ef7d4122bfe5 (patch) | |
tree | 7cef8247a415343cbf86816fe1a0c09534853390 /Lib/argparse.py | |
parent | 0331e906d6a3e52b2679284cebd71a2513a00bfe (diff) | |
parent | 8d9a4628c35811a803bde626c76573c722beea03 (diff) | |
download | cpython-edbe4c5249cb96dfe55e114de998ef7d4122bfe5.zip cpython-edbe4c5249cb96dfe55e114de998ef7d4122bfe5.tar.gz cpython-edbe4c5249cb96dfe55e114de998ef7d4122bfe5.tar.bz2 |
Issue #9348: Raise an early error if argparse nargs and metavar don't match. (Merge from 3.2.)
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 2d8ed38..0abfb36 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -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): |