[issue21666] Argparse exceptions should include which argument has a problem

paul j3 report at bugs.python.org
Sat Jun 7 18:19:27 CEST 2014


paul j3 added the comment:

First, 'parse_intermixed_args' on stack is not relevant.  It's from an unreleased patch that we worked on.

What matters is the 'print_help', invoked probably with a '-h'.

The error message that normally specifies the problem argument is produced by ArgumentError.  The HelpFormatter does not raise such an error.  ArgumentError is usually used for parsing errors; this is a formatting one.  It's not produced by faulty commandline values.

If you must put strings like '%)` in the help line, use RawTextHelpFormatter.  Otherwise HelpFormatter assumes the help line has valid format expressions like '%(default)s'.

Or you could write your own HelpFormatter subclass with a modified '_expand_help' method, one which wraps the 'self._get_help_string(action) % params' in a 'try' block.  Probably too draconian a measure for a rare problem. :)  

It's an interesting problem, but I don't think it warrants any code changes.

----------
nosy: +paul.j3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21666>
_______________________________________


More information about the Python-bugs-list mailing list