paul j3 <ajipa...@gmail.com> added the comment:

I didn't pay attention to the patch that added this "exit_on_error" parameter.  
So I don't know exactly what error handling it was supposed to handle or why.  
But given the location of the code change, it does not handle every possible 
error.

Specifically it's  in parser.parse_known_args() where it calls 
_parse_known_args().  With this parameter True, a argparse.ArgumentError is 
caught and converted to parse.error() call.  That's the original behavior.

With False, there's no special handling for ArgumentError.  Catching that is 
left to the developer, as illustrated in the docs.

In the documented example, it's a 'type' error. 'choices' would also behave 
this way. 'nargs' errors also.  But not all errors are handled like this.

Inside _parse_known_args(), `self.error()` is called several times, once for 
'required' arguments failure, and for a required mutually_exclusive_group 
error.  I count 9 self.error() calls; exit_on_error only changes one of those.

The error highlighted in this issue is called in parser.parse_args().  This 
calls parse_known_args(), and raises an error if there are 'extras', 
unrecognized strings.

So clearly the new docs is is describing this new parameter in overly broad 
terms.  It only changes the handling of a subset of parser.error() calls.  Off 
hand I can't think of clean way of refining the description without getting 
overly technical about the error handling.

Developers already had the documented option of changing the parse.error() and 
parse.exit() methods.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41255>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to