Bug report
When ArgumentParser encounters certain errors, it calls self.error(...) which exits, even when exit_on_error is set to False.
This prevents catching the exception and writing a custom error message.
importargparseparser=argparse.ArgumentParser(exit_on_error=False)
parser.add_argument('filename')
try:
args=parser.parse_args([])
exceptException:
print("Bad argument, here's what you should do instead...")Test on Python 3.11.3:
python argparse-bug/repro.pyusage: repro.py [-h] filenamerepro.py: error: the following arguments are required: filename
Linked PRs
Bug report
When
ArgumentParserencounters certain errors, it callsself.error(...)which exits, even whenexit_on_erroris set to False.This prevents catching the exception and writing a custom error message.
Test on Python 3.11.3:
Linked PRs