Message187686
This patch adds a value test for nargs during add_argument. The core of the new test is in ArgumentParser._check_argument.
add_argument() now calls ArgumentParser._check_argument(), which calls _format_args(). If it gets a TypeError, it raises a metavar ValueError as before. But if it gets an ValueError, it raises an ArgumentError.
An argument group gets the _check_argument method from its container. This way, check_argument() works for both parsers and groups.
HelpFormater _format_args() now raises a ValueError if the nargs is not an integer (or one of the recognized strings).
What kind of error should we produce when there is a problem with nargs?
An ArgumentError has the advantage that it includes the action name. But the metavar tuple test was coded to raise ValueError. Plus the test_argparse.py TestInvalidArgumentConstructors class tests all check for TypeError or ValueError.
I have kept the metavar tuple case as ValueError. That way, test_argparse.py runs without a change. I still need to add tests for invalid string nargs values. And I think the case could be made for returning ArgumentValue errors. |
|
Date |
User |
Action |
Args |
2013-04-24 06:22:54 | paul.j3 | set | recipients:
+ paul.j3, bethard, eric.araujo, Jason.Baker, BreamoreBoy |
2013-04-24 06:22:54 | paul.j3 | set | messageid: <1366784574.22.0.727329343544.issue9849@psf.upfronthosting.co.za> |
2013-04-24 06:22:54 | paul.j3 | link | issue9849 messages |
2013-04-24 06:22:53 | paul.j3 | create | |
|