[New-bugs-announce] [issue11874] argparse assertion failure with brackets in metavars

Hartmut Niemann report at bugs.python.org
Tue Apr 19 10:20:52 CEST 2011


New submission from Hartmut Niemann <Hartmut.Niemann at siemens.com>:

I run this script with option --help
-----8<------------------
import argparse
parser = argparse.ArgumentParser()
parser.add_argument ('--from-itm', dest="from_itm",action="store",default=None,help ="Source ITM file", metavar="ITMFILENAME")
parser.add_argument ("--from-fbm-sigtab",dest="from_sigtab",action="store",default=None,help="Source signal FB", metavar=" [LIB,]FBNAME")
parser.add_argument ("--c",dest="f",metavar="x]d")
args = parser.parse_args()
---------8<--------------------
and I get an assertion failure:
---------8<--------------------
D:\temp>argparsebug.py --help
Traceback (most recent call last):
  File "D:\temp\argparsebug.py", line 6, in <module>
    args = parser.parse_args()
  File "C:\Python27\lib\argparse.py", line 1678, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "C:\Python27\lib\argparse.py", line 1710, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "C:\Python27\lib\argparse.py", line 1916, in _parse_known_args
    start_index = consume_optional(start_index)
  File "C:\Python27\lib\argparse.py", line 1856, in consume_optional
    take_action(action, args, option_string)
  File "C:\Python27\lib\argparse.py", line 1784, in take_action
    action(self, namespace, argument_values, option_string)
  File "C:\Python27\lib\argparse.py", line 993, in __call__
    parser.print_help()
  File "C:\Python27\lib\argparse.py", line 2303, in print_help
    self._print_message(self.format_help(), file)
  File "C:\Python27\lib\argparse.py", line 2277, in format_help
    return formatter.format_help()
  File "C:\Python27\lib\argparse.py", line 278, in format_help
    help = self._root_section.format_help()
  File "C:\Python27\lib\argparse.py", line 208, in format_help
    func(*args)
  File "C:\Python27\lib\argparse.py", line 329, in _format_usage
    assert ' '.join(opt_parts) == opt_usage
AssertionError
--------------8<-------------------------------
It must be the combination of several argument lines because when I 
comment out one of the add_arguments, it works.

Is this a bug or do I do things I shouln't?
If it is not allowed to use [] in metavars (what I wanted was metavar='[optional,]mantatory'), I' like to receive a readable error message.

With best regards
Hartmut Niemann

----------
components: None
messages: 134021
nosy: htnieman
priority: normal
severity: normal
status: open
title: argparse assertion failure with brackets in metavars
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11874>
_______________________________________


More information about the New-bugs-announce mailing list