zenlotus / argparse

Automatically exported from code.google.com/p/argparse
Other
0 stars 0 forks source link

Calling add_argument with the wrong number of metavars causes delayed error message. #67

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

What version of the product are you using? On what operating system?

argparse 1.0 on Debian Linux

Original issue reported on code.google.com by Karatorian on 14 Mar 2010 at 3:51

GoogleCodeExporter commented 9 years ago
Here's a little example that uses a bunch of variations to trigger the bug. It 
could
be the basis of some sort of test.

Original comment by Karatorian on 14 Mar 2010 at 4:13

Attachments:

GoogleCodeExporter commented 9 years ago
Moved to http://bugs.python.org/issue9348

Original comment by steven.b...@gmail.com on 23 Jul 2010 at 1:34