-
- Notifications
You must be signed in to change notification settings - Fork 33.6k
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
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.
import argparse parser = argparse.ArgumentParser(exit_on_error=False) parser.add_argument('filename') try: args = parser.parse_args([]) except Exception: print("Bad argument, here's what you should do instead...")Test on Python 3.11.3:
python argparse-bug/repro.py usage: repro.py [-h] filename repro.py: error: the following arguments are required: filenameLinked PRs
baolsen, SamuelLorrain, john-hen and VijitCoder
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Doc issues