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 paul.j3
Recipients BreamoreBoy, Jason.Baker, bethard, eric.araujo, paul.j3
Date 2013-04-24.06:22:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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 TestInvalidArgumentConstructors class tests all check for TypeError or ValueError.

I have kept the metavar tuple case as ValueError.  That way, 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:54paul.j3setrecipients: + paul.j3, bethard, eric.araujo, Jason.Baker, BreamoreBoy
2013-04-24 06:22:54paul.j3setmessageid: <>
2013-04-24 06:22:54paul.j3linkissue9849 messages
2013-04-24 06:22:53paul.j3create