This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bethard
Recipients bethard
Date 2010-07-23.13:34:14
SpamBayes Score 0.0005365299
Marked as misclassified No
Message-id <>
What steps will reproduce the problem?

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

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)

and makes sure that the error shows up in add_argument, not format_help.
Date User Action Args
2010-07-23 13:34:16bethardsetrecipients: + bethard
2010-07-23 13:34:16bethardsetmessageid: <>
2010-07-23 13:34:14bethardlinkissue9348 messages
2010-07-23 13:34:14bethardcreate