[New-bugs-announce] [issue46440] ArgumentParser.parse_args exits on missing required argument with exit_on_error=False

Daniel Schulte report at bugs.python.org
Wed Jan 19 16:04:30 EST 2022


New submission from Daniel Schulte <trilader at schroedingers-bit.net>:

When calling ArgumentParser.parse_args(list_of_things_to_parse) sys.exit gets called even though the parser was constructed with exit_on_error=False. It doesn't matter if the parser has any subparsers added or not.

The docs say
> Normally, when you pass an invalid argument list to the parse_args() 
> method of an ArgumentParser, it will exit with error info.

> If the user would like to catch errors manually, the feature can be 
> enabled by setting exit_on_error to False:
> [example code follows]

The docs make me believe what I'm trying to do should work.
I've attached a minimal working example to show what happens (with and without subparsers).

----------
components: Library (Lib)
files: bug.py
messages: 410984
nosy: trilader
priority: normal
severity: normal
status: open
title: ArgumentParser.parse_args exits on missing required argument with exit_on_error=False
type: behavior
versions: Python 3.10
Added file: https://bugs.python.org/file50567/bug.py

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


More information about the New-bugs-announce mailing list