homepage

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 Radu.Ciorba, bethard, chris.jerdonek, paul.j3, r.david.murray, terry.reedy
Date 2013年07月01日.06:26:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1372659989.34.0.282834217356.issue16468@psf.upfronthosting.co.za>
In-reply-to
Content
chris.jerdonek wrote:
"Also, to answer a previous question, the three places in which the choices string is used are: in the usage string (separator=','), in the help string when expanding "%(choices)s" (separator=', '), and in the error message text (separator=', ' with repr() instead of str())."
In the usage string, the ',' is used to make a compact representation of the choices. The ', ' separator is used in the help line, where space isn't as tight. 
This 'choices formatting' is called during 'add_argument()' simply as a side effect of checking for valid parameters, especially 'nargs' (that it, is an integer or an acceptable string). Previously 'nargs' errors were not caught until 'parse_args' was used. This is discussed in
http://bugs.python.org/issue9849 Argparse needs better error handling for nargs
http://bugs.python.org/issue16970 argparse: bad nargs value raises misleading message 
On the issue of what error type to raise, my understanding is that 'ArgumentError' is the preferred choice when it affects a particular argument. parse_args() nearly always raises an ArgumentError. Once add_argument has created an action, it too can raise an ArgumentError. ArgumentError provides a standard way of identifying which action is giving the problem.
 
While testing 'metavar="range(0,20)"', I discovered that the usage formatter strips off parenthesis. A regex expression that removes 
excess 'mutually exclusive group' notation is responsible for this. The simple fix is to modify the regex so it distinguishes between ' (...)' and 'range(...)'. I intend to create a new issue for this, since it affects any metavar the includes ().
History
Date User Action Args
2013年07月01日 06:26:29paul.j3setrecipients: + paul.j3, terry.reedy, bethard, r.david.murray, chris.jerdonek, Radu.Ciorba
2013年07月01日 06:26:29paul.j3setmessageid: <1372659989.34.0.282834217356.issue16468@psf.upfronthosting.co.za>
2013年07月01日 06:26:29paul.j3linkissue16468 messages
2013年07月01日 06:26:28paul.j3create

AltStyle によって変換されたページ (->オリジナル) /