[issue41255] Argparse.parse_args exits on unrecognized option with exit_on_error=False
paul j3
report at bugs.python.org
Sat Sep 11 01:39:07 EDT 2021
paul j3 <ajipanca at gmail.com> added the comment:
In
https://stackoverflow.com/questions/69108632/unable-to-catch-exception-error-for-argparse
it looked like `exit_on_error` does not work when using subparsers. On on further thought, I realized that it has to included in the definition of the subparser. As with other `ArgumentParser` parameters, the subparsers does not inherit from the main parser.
So it's basically a documentation issue. The `add_parser` method is described briefly as:
which takes a command name and any ArgumentParser constructor
arguments, and returns an ArgumentParser object that can be
modified as usual.
But as my experience shows, its relevance is easily missed, even by an experienced users.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41255>
_______________________________________
More information about the Python-bugs-list
mailing list