New submission from Steven Bethard <[email protected]>:

What steps will reproduce the problem?

parser = argparse.ArgumentParser()      
parser.add_argument('--foo', nargs=2, metavar=('X','Y','Z'))
parser.parse_args(['-h'])

The error dosn't show up until help is formatted.

Giving any incorrect length of metavar will produce the problem, which
includes a tuple whos length doesn't match a numerical value, more than two 
metavars to '*' or '+', and more than one metavar to '?'. Furthermore, a tuple 
of length one causes the error when nargs is greater than 1, '*', or '+'.

What is the expected output? What do you see instead?

When the help is displayed, you get:

TypeError: not all arguments converted during string formatting

Or a similar error message for other cases.

It would be expected that the error message would be more specific. The
error should definitely be raised when add_argument is called, rather than 
later.

There should be a test that does something like:

    for meta in ('X', ('X',), ('X','Y'), ('X','Y','Z')):
        for n in (1, 2, 3, '?', '+', '*'):
            parser = argparse.ArgumentParser()
            parser.add_argument('--foo', nargs=n, metavar=meta)
            parser.format_help()

and makes sure that the error shows up in add_argument, not format_help.

----------
components: Library (Lib)
messages: 111317
nosy: bethard
priority: normal
severity: normal
stage: needs patch
status: open
title: Calling argparse's add_argument with the wrong number of metavars causes 
delayed error message
type: behavior
versions: Python 2.7, Python 3.2

_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue9348>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to