Author m_khvoinitsky
Recipients m_khvoinitsky
Date 2020-12-02.21:15:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1606943750.61.0.237402460323.issue42547@roundup.psfhosted.org>
In-reply-to
Content
Example which works:

    parser.add_argument('--test', nargs='+', metavar=('TEST', 'TEST2'))



Example which doesn't work:

    parser.add_argument('test', nargs='+', metavar=('TEST', 'TEST2'))

it raises:

    Traceback (most recent call last):
      File <omitted>
        args = parser.parse_args()
      File "/usr/lib/python3.8/argparse.py", line 1768, in parse_args
        args, argv = self.parse_known_args(args, namespace)
      File "/usr/lib/python3.8/argparse.py", line 1800, in parse_known_args
        namespace, args = self._parse_known_args(args, namespace)
      File "/usr/lib/python3.8/argparse.py", line 2006, in _parse_known_args
        start_index = consume_optional(start_index)
      File "/usr/lib/python3.8/argparse.py", line 1946, in consume_optional
        take_action(action, args, option_string)
      File "/usr/lib/python3.8/argparse.py", line 1874, in take_action
        action(self, namespace, argument_values, option_string)
      File "/usr/lib/python3.8/argparse.py", line 1044, in __call__
        parser.print_help()
      File "/usr/lib/python3.8/argparse.py", line 2494, in print_help
        self._print_message(self.format_help(), file)
      File "/usr/lib/python3.8/argparse.py", line 2471, in format_help
        formatter.add_arguments(action_group._group_actions)
      File "/usr/lib/python3.8/argparse.py", line 276, in add_arguments
        self.add_argument(action)
      File "/usr/lib/python3.8/argparse.py", line 261, in add_argument
        invocations = [get_invocation(action)]
      File "/usr/lib/python3.8/argparse.py", line 549, in _format_action_invocation
        metavar, = self._metavar_formatter(action, default)(1)
    ValueError: too many values to unpack (expected 1)


Expected result: help message should look like this:

    usage: test_argparse [-h] TEST [TEST2 ...]

    positional arguments:
      TEST

    optional arguments:
      -h, --help  show this help message and exit
History
Date User Action Args
2020-12-02 21:15:50m_khvoinitskysetrecipients: + m_khvoinitsky
2020-12-02 21:15:50m_khvoinitskysetmessageid: <1606943750.61.0.237402460323.issue42547@roundup.psfhosted.org>
2020-12-02 21:15:50m_khvoinitskylinkissue42547 messages
2020-12-02 21:15:50m_khvoinitskycreate