[issue39333] argparse should offer an alternative to SystemExit in case a parse fails

Jack Orenstein report at bugs.python.org
Tue Jan 14 15:36:54 EST 2020


New submission from Jack Orenstein <jao at geophile.com>:

If parse_args fails, SystemExit is raised, carrying an exit code of 2, and the help message is printed. For an embedded usage of argparse, this behavior is undesirable.

I am writing an interactive console application, using argparse to parse input. When a parse fails, I would like to print an error message and continue, not terminate the program. Currently, I need to catch SystemExit to be able to do this, which has obvious problems, (e.g., what if something other that argparse is causing the exit?)

I'd like to see some way to specify alternative behavior, e.g. raise an exception of a given type.

----------
components: Library (Lib)
messages: 359991
nosy: geophile
priority: normal
severity: normal
status: open
title: argparse should offer an alternative to SystemExit in case a parse fails
type: enhancement

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39333>
_______________________________________


More information about the Python-bugs-list mailing list