diff options
author | steven.bethard <devnull@localhost> | 2009-10-24 15:54:32 +0000 |
---|---|---|
committer | steven.bethard <devnull@localhost> | 2009-10-24 15:54:32 +0000 |
commit | 57dee9ad3d9f5621f7136988d167edcce2db6100 (patch) | |
tree | 7062a1fd4d2d2dd8426504be1b7c356fb0a81682 | |
parent | bc9332c5e33065a637797d739363236b01eb57d3 (diff) | |
download | argparse-57dee9ad3d9f5621f7136988d167edcce2db6100.tar.gz |
Better error messages when 'dest' occurs twice for positional arguments
-rw-r--r-- | NEWS.txt | 1 | ||||
-rw-r--r-- | argparse.py | 2 | ||||
-rw-r--r-- | test/test_argparse.py | 11 |
3 files changed, 14 insertions, 0 deletions
@@ -3,6 +3,7 @@ What's New in argparse 1.1 - Issue #36: Get "from argparse import *" working - Issue #37: Stop treating two character alphanumeric flags as numbers +- Issue #38: Better error messages when 'dest' occurs twice for positional arguments - Issue #39: Better error messages for invalid actions diff --git a/argparse.py b/argparse.py index 503cbaf..3cc3b6a 100644 --- a/argparse.py +++ b/argparse.py @@ -1249,6 +1249,8 @@ class _ActionsContainer(object): # argument chars = self.prefix_chars if not args or len(args) == 1 and args[0][0] not in chars: + if args and 'dest' in kwargs: + raise ValueError('dest supplied twice for positional argument') kwargs = self._get_positional_kwargs(*args, **kwargs) # otherwise, we're adding an optional argument diff --git a/test/test_argparse.py b/test/test_argparse.py index c1717dc..a1c674c 100644 --- a/test/test_argparse.py +++ b/test/test_argparse.py @@ -3624,6 +3624,17 @@ class TestInvalidArgumentConstructors(TestCase): msg = 'expected %r, found %r' % (expected, e) self.failUnless(expected in str(e), msg) + def test_multiple_dest(self): + parser = argparse.ArgumentParser() + parser.add_argument(dest='foo') + try: + parser.add_argument('bar', dest='baz') + except ValueError: + e = sys.exc_info()[1] + expected = 'dest supplied twice for positional argument' + msg = 'expected %r, found %r' % (expected, e) + self.failUnless(expected in str(e), msg) + def test_no_argument_actions(self): for action in ['store_const', 'store_true', 'store_false', 'append_const', 'count']: |