New submission from Tshepang Lekhonkhobe <tshep...@gmail.com>: Here's four commands to demonstrate my problem:
My sample code: $ cat prog.py import argparse parse = argparse.ArgumentParser() parse.add_argument("foo", nargs=2, metavar=("foo", "bar")) args = parse.parse_args() print(args) This output could be friendlier: $ python3 prog.py --help Traceback (most recent call last): File "prog.py", line 4, in <module> args = parse.parse_args() File "/home/wena/cpython/Lib/argparse.py", line 1722, in parse_args args, argv = self.parse_known_args(args, namespace) File "/home/wena/cpython/Lib/argparse.py", line 1754, in parse_known_args namespace, args = self._parse_known_args(args, namespace) File "/home/wena/cpython/Lib/argparse.py", line 1960, in _parse_known_args start_index = consume_optional(start_index) File "/home/wena/cpython/Lib/argparse.py", line 1900, in consume_optional take_action(action, args, option_string) File "/home/wena/cpython/Lib/argparse.py", line 1828, in take_action action(self, namespace, argument_values, option_string) File "/home/wena/cpython/Lib/argparse.py", line 1015, in __call__ parser.print_help() File "/home/wena/cpython/Lib/argparse.py", line 2347, in print_help self._print_message(self.format_help(), file) File "/home/wena/cpython/Lib/argparse.py", line 2314, in format_help formatter.add_arguments(action_group._group_actions) File "/home/wena/cpython/Lib/argparse.py", line 270, in add_arguments self.add_argument(action) File "/home/wena/cpython/Lib/argparse.py", line 255, in add_argument invocations = [get_invocation(action)] File "/home/wena/cpython/Lib/argparse.py", line 533, in _format_action_invocation metavar, = self._metavar_formatter(action, default)(1) ValueError: too many values to unpack (expected 1) On Python 3.2 (from Debian), I get "error: too few arguments". But with latest mercurial I get: $ python3 prog.py Traceback (most recent call last): File "prog.py", line 4, in <module> args = parse.parse_args() File "/home/wena/cpython/Lib/argparse.py", line 1722, in parse_args args, argv = self.parse_known_args(args, namespace) File "/home/wena/cpython/Lib/argparse.py", line 1754, in parse_known_args namespace, args = self._parse_known_args(args, namespace) File "/home/wena/cpython/Lib/argparse.py", line 1973, in _parse_known_args ', '.join(required_actions)) TypeError: sequence item 0: expected str instance, tuple found But this looks okay: $ python3 prog.py a b Namespace(foo=['a', 'b']) ---------- components: Library (Lib) messages: 153884 nosy: tshepang priority: normal severity: normal status: open title: argparse does not allow nargs>1 for positional arguments but doesn't allow metavar to be a tuple versions: Python 3.3 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue14074> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com