This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ArgumentParser.parse_args exits on missing required argument with exit_on_error=False
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: jacobtylerwalls, paul.j3, trilader
Priority: normal Keywords: patch

Created on 2022-01-19 21:04 by trilader, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug.py trilader, 2022-01-19 21:04
Pull Requests
URL Status Linked Edit
PR 30832 open jacobtylerwalls, 2022-01-23 17:17
Messages (2)
msg410984 - (view) Author: Daniel Schulte (trilader) Date: 2022-01-19 21:04
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).
msg412376 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2022-02-02 16:52
Duplicate of https://bugs.python.org/issue41255

Argparse.parse_args exits on unrecognized option with exit_on_error=False
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90598
2022-02-02 16:52:20paul.j3setstatus: open -> closed

nosy: + paul.j3
messages: + msg412376

resolution: duplicate
stage: patch review -> resolved
2022-01-23 17:17:27jacobtylerwallssetkeywords: + patch
nosy: + jacobtylerwalls

pull_requests: + pull_request29018
stage: patch review
2022-01-19 21:04:30triladercreate